% 1. Greetings
fprintf(['\n Welcome! This program integrates and plots a 2D function of x. You may now choose your integration method.' ... ' \n Enter ''1'' for Rectangle Rule; ''2'' for Trapezium Rule; and ''3'' for Simpson''s Rule. \n\n'])C = input ('Enter your choice = '); % Variable 'C' is chosen as 'C' for Choice
if C == 1; run Rectangle_Ruleelseif C == 2; run Trapezium_Ruleelseif C == 3; run Simpsons_Ruleelse fprintf(['\n ------------------------------------------------------------------------------------------------------------' ... '\n OPTION INVALID. PLEASE TRY AGAIN.'... '\n ------------------------------------------------------------------------------------------------------------ \n']) run Numeric_Integrationend
I want the fprintf and re-run of numeric integration to work at all cases. The code above works fine when what is input is a number or a an alphabet with apostrophes, e.g., 'code', 'A'; but if it is just a letter with no apostrophes, it doesn't *. For example, I try to enter *test This message appears:
Error using inputUndefined function or variable 'test'.Error in Numeric_Integration (line 7)C = input ('Enter your choice = '); % Variable 'C' is chosen as 'C' for Choice
How do I go around this problem?
Also, is there anyway that when it loops back to give the user another try to not show the welcome message again – this is what happens if I use run Numeric_Integration after else. Is there a code to make it just loop back to C = input ('Enter your choice = '); ?
Cheers
Best Answer