I want to determine whether the user wishes to work with their angles in degrees or radians
1 view (last 30 days)
Show older comments
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 Comment
Walter Roberson
on 30 Oct 2012
Please use better tags for this question; see http://www.mathworks.co.uk/matlabcentral/answers/43073-a-guide-to-tags
Answers (2)
Walter Roberson
on 30 Oct 2012
input() expects numeric input unless you use the 's' option.
If you want to compare strings, use strcmp() or strcmpi()
0 Comments
dimitris
on 30 Oct 2012
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 Comments
See Also
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!