Guided PracticeUsing Else…If Statements to make Multiple Decisions
The following program uses multiple else…if statements to compare user-entered values. Specific conditions are checked and messages are displayed based upon if the first number is greater than the second, if the first number is less than the second, or if the numbers are equal.
The else..if statement is useful when you need to check multiple conditions within the program, nesting of if-else blocks can be avoided by using else..if statement. Only the statements inside the body of the “if” are executed. This is because in this statement as soon as a condition is satisfied, the statements inside that block are executed and the rest of the blocks are ignored.
Important Points: 1. else and else..if are optional statements, a program having only “if” statement would run fine. 2. else and else..if cannot be used without the “if”. 3. There can be any number of else..if statements in an if else..if block. 4. If none of the conditions are met then the statements in the else block get executed.
Follow these instructions to complete your assignment:
1. Use Flowgorithm to create the flowchart in the tab below.
2. Select the Code tab and enter the code into your compiler.
3. Compile your code and run. Your output should match the image on the Output tab.
4. Paste your flowchart and a screenshot of your output (including the Title Bar showing the path and name of your code) into a Word document (.docx).
5. Submit the “.c” code file, which should include a comment line with your name and the date.
6. Submit the Flowgorithm (.fprg) file.
7. Save your files and upload them using the instructions below.
New flowchart syntax: Take notice of the & sign next to the variable name in the output statements – To attach text to a value stored in a variable (concatenation) you need to include the & symbol right next to the ” double-quotes.