I want to determine whether the user wishes to work with their angles in degrees or radians
1 回表示 (過去 30 日間)
古いコメントを表示
Hi, I have written the following code to determine whether the user want their angle to be calculated in degrees or in radians
type= input('Enter D to work angle in degrees or R for radians')
V= input('Enter velocity ');
a= input('Enter angle ');
cosine;
sine;
if (type==r | R)
cosine=cos;
sine=sin;
elseif (type==d | D)
cosine=cosd;
sine=sind;
else
output('You failed to input a correct answer');
end
It won't work for me. I would also liek to allow the user to be able to reinput their choice in the last else statement in case they hit an invalid key.
Thanks Chris
1 件のコメント
Walter Roberson
2012 年 10 月 30 日
Please use better tags for this question; see http://www.mathworks.co.uk/matlabcentral/answers/43073-a-guide-to-tags
回答 (2 件)
Walter Roberson
2012 年 10 月 30 日
input() expects numeric input unless you use the 's' option.
If you want to compare strings, use strcmp() or strcmpi()
0 件のコメント
dimitris
2012 年 10 月 30 日
type= input('Enter D to work angle in degrees or R for radians')
V= input('Enter velocity ');
a= input('Enter angle ');
cosine;
sine;
if (type==r | R)
cosine=cos(a);
sine=sin(a);
elseif (type==d | D)
cosine=cosd(a);
sine=sind(a);
else
type=input('You failed to input a correct answer, press r for rads or d for degrees');
if (type==r | R)
cosine=cos(a);
sine=sin(a);
elseif (type==d | D)
cosine=cosd(a);
sine=sind(a);
else
end
Or you can use a while loop if you want the user to reinput his choice until it's correct.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!