Do you get the expected results engineering education

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: r adding the four ‘input’ assignment statements save and run your code. Do you get the expected results? Engineering Education input syntax user General Form: Var = input (' user prompt ' ) ; Example: R = input ('\nEnter the radius , R: ' ) ; User prompt The text in purple, except for the \n, will appear in the command window to prompt the user for input. The \n is a control sequence that causes the prompt to be printed on a new line, not required. An input statement is a special kind of value assignment statement, don’t forget the semi-colon How would we tell the user what units to use? Engineering Education Trip Decision If the goal of this program is to determine if the trip is feasible with the given budget……….. We can determine this by comparing the cost of the trip to the budget. Since we want to do one thing if COST<= BUDGET and another if it is not, we will use an if-else-end structure: %Decision if COST<=BUDGET fprintf('\nGO!\n') else fprintf('\nNO!\n') end Notice the quotes around NO and GO in the flowchart Engineering Education Basic Decision Structures (if-else(if-else-end) If If one action is needed when a condition is true, and a different action is needed when the condition if false if (condition) statements to execute when true else statements to execute when false end Relational Operators: > < == >= <= ~= condition compares a variable to a value x<3 Y == ‘P’ Statement can be any number of executable statements including input, fprintf, and calculations Engineering Education...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online