If statements and strcmp function
Show older comments
Given: strcmp = matching case, strcmpi=ignoring case
Find: Prompt user to enter an angle; prompt user to determine if the angle was provided in degrees or radians; write an if statement that calculates the sine of the angle using the sin function if the units were in radians or sind if the units were degrees.
Issue: I created a flow chart, wrote my code, but it's not giving me what I want, grrrrr. Shows the same output for degrees and radians.
My solution:
angle=input('Enter an angle: ');
units=input('Is it in degrees or radians? ','s');
if sin(angle) % if 45 degrees should be 0.0123413415 radians
fprintf('The sine of your angle is %3.1f %s.\n',sin(angle),units)
elseif sind(angle) % if 45 degrees should be sqrt(2)/2=0.7071
fprintf('The sine of your angle is %3.1f %s.\n',sind(angle),units)
end
Accepted Answer
More Answers (0)
Categories
Find more on Programming 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!