Applying a string of user inputs within a while-loop
Show older comments
Hi folks, realy new to MATLABS and with the recent events forcing campus closure I am having some difficulties without the in class help from the instructor.
I am attempting to code a simple calculator for projectile motion and have come up with thus so far:
How can I use the while loop to request whether or not to continue with the calculation? Really am not sure what I am doing incorrectly here.
This is the error I am presented with: Line 11, Collumn 5: "At least one END is missing: the statement may begin here."
Thank you for any help!
angle=input(['Enter the angle of trajectory [degrees] : '])
height=input(['Enter the height at which the projectile will be launched [feet] : '])
velocity=input(['Enter the velocity as the projectile is initially launched [feet/second] : '])
disp(['You have selected: ANGLE = ' num2str(angle,'%5.3f') ' degrees; HEIGHT = ' num2str(height,'%10.3f') ' feet; VELOCITY= ' num2str(velocity,'%10.3f') ' ft/s'])
while resume=input(['Would you like to continue with these calculations?','s'])
quit='NO'
cont='YES'
if ischar(resume) && strcmp(resume,quit)
disp(['Restarting caclulations...'])
break
else if ischar(resume) && strcmp(resume,cont)
disp(['Solving for projectile motion...'])
continue
end
Accepted Answer
More Answers (1)
David Hill
on 1 Apr 2020
Recommend breaking while loop with if statement:
while 1
angle=input(['Enter the angle of trajectory [degrees] : ']);
height=input(['Enter the height at which the projectile will be launched [feet] : ']);
velocity=input(['Enter the velocity as the projectile is initially launched [feet/second] : ']);
disp(['You have selected: ANGLE = ' num2str(angle,'%5.3f') ' degrees; HEIGHT = ' num2str(height,'%10.3f') ' feet; VELOCITY= ' num2str(velocity,'%10.3f') ' ft/s']);
%put calculation here
resume=input(['Would you like to continue with these calculations?','s']);
if isequal(lower(resume),'no')||isequal(lower(resume),'n')
break;
end
end
1 Comment
Categories
Find more on Loops and Conditional Statements 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!