How can I take a user input and use that in an equation?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Dylan Blosser
am 25 Nov. 2019
Kommentiert: Dylan Blosser
am 25 Nov. 2019
I am writing a code to ask the user a series of questions. Once they enter their time I want to calculate that amount of time into hours. How do I take the user input and put that into an equation?
n=input('Are you entering in milliseconds or seconds? Enter 1 for milliseconds or 2 for seconds. ');
if n==1;
disp('Enter time in ms: ');
else n==2;
disp('Enter time in sec: ');
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 25 Nov. 2019
units_opts = {'milliseconds', 'seconds', 'fortnights'};
units_ms_scale = [1 1000 14*24*60*60*1000];
n = menu('Time units:', units_opts);
if n < 1; return; end %user cancel
user_entered_time = input( sprintf('Enter the time, in %s', units_opts{n}) );
user_time_ms = user_entered_time * units_ms_scale(n);
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!