How can I take a user input and use that in an equation?
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Walter Roberson
2019 年 11 月 25 日
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);
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!