Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

How to run this code?

1 Ansicht (letzte 30 Tage)
Swapnil srivastava
Swapnil srivastava am 25 Apr. 2017
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
A=input('What would you like to do?: ','s');
if strcmp(A,'add book')
Tit= input('Ask for title: ','s');
Aut=input('Ask for author: ','s');
No_pg=input('Ask for number of pages: ','s');
fprintf('Title: %s \n',Tit)
fprintf('Author: %s \n',Aut)
fprintf('Number of pages: %s \n',No_pg)
elseif strcmp(A,'quit')
disp('Good bye')
else
disp('Nothing entered')
end
  2 Kommentare
Jan
Jan am 25 Apr. 2017
The question is not clear. Most likely you can either run this in the command window or write it to a script or function M-file to start it from there. Please explain which problem you have with running this code.
Swapnil srivastava
Swapnil srivastava am 26 Apr. 2017
if i prompt 'add book'on A then the computer asks for the title, author and number of pages for the book and display them. If i 'prompt'quit, then it displays 'goodbye'. Basically when i type add book the code runs fine but if i type quit it doesnt run

Antworten (1)

KSSV
KSSV am 25 Apr. 2017
A=input('What would you like to do?: ','s');
if strcmp(A,'add book')
Tit= input('Ask for title: ','s');
Aut=input('Ask for author: ','s');
No_pg=input('Ask for number of pages: ','s');
fprintf('Title: %s \n',Tit)
fprintf('Author: %s \n',Aut)
fprintf('Number of pages: %s \n',No_pg)
elseif strcmp(A,'hi')
disp('Good bye')
else
disp('Nothing entered')
end
  2 Kommentare
Jan
Jan am 25 Apr. 2017
Do I see correctly: This is the original code with 'quit' replaced by 'hi'?
KSSV
KSSV am 25 Apr. 2017
There was no strcmp, question had == . I suspect I have edited the question instead of answer.

Diese Frage ist geschlossen.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by