Chapter 4: Problem 18
How do you write a multiple alternative decision structure in pseudocode?
Short Answer
Expert verified
Answer: The output will be "Average".
Step by step solution
01
Define the problem
First, it's important to understand the problem that requires a multiple alternative decision structure. Let's consider a problem where the user must input a grade, and the program must output whether the grade is excellent, good, average, or poor.
02
Begin pseudocode with user input
Start the pseudocode by asking the user to input the grade and store it in a variable called "grade":
```
READ grade
```
03
Write the first conditional statement
Begin the multiple alternative decision structure with an 'if' statement to check if the grade is excellent, i.e., greater than or equal to 90:
```
IF grade >= 90 THEN
OUTPUT "Excellent"
```
04
Use 'else if' for further conditions
Write 'else if' statements to check for other conditions, like if the grade is good, average, or poor. For example, if the grade is between 80 and 89, the output should be "Good":
```
ELSE IF grade >= 80 THEN
OUTPUT "Good"
```
05
Continue with 'else if' for additional conditions
Add more 'else if' statements for the other conditions, for example for a grade between 70 and 79, the output should be "Average":
```
ELSE IF grade >= 70 THEN
OUTPUT "Average"
```
06
Use 'else' for the last condition
For the last condition, use an 'else' statement when none of the previous conditions are met. In this case, a grade less than 70, the output should be "Poor":
```
ELSE
OUTPUT "Poor"
```
07
End the decision structure
Lastly, close the multiple alternative decision structure using 'END IF':
```
END IF
```
08
Final pseudocode
Here is the complete pseudocode for a multiple alternative decision structure that evaluates a grade input:
```
READ grade
IF grade >= 90 THEN
OUTPUT "Excellent"
ELSE IF grade >= 80 THEN
OUTPUT "Good"
ELSE IF grade >= 70 THEN
OUTPUT "Average"
ELSE
OUTPUT "Poor"
END IF
```
Unlock Step-by-Step Solutions & Ace Your Exams!
-
Full Textbook Solutions
Get detailed explanations and key concepts
-
Unlimited Al creation
Al flashcards, explanations, exams and more...
-
Ads-free access
To over 500 millions flashcards
-
Money-back guarantee
We refund you if you fail your exam.
Over 30 million students worldwide already upgrade their learning with Vaia!