In this lab you will practice prompting the user for a character value, reading the value from the user/keyboard into a char variable, and using a switch statement to print out a value range based on the character entered. Be sure to read this lab thoroughly, especially the Hand-in Procedure.
Write a complete program that:
Prompts the user to enter a letter grade and reads in a letter grade from the keyboard as a char.
Uses a switch statement to output the appropriate range for the grade entered in (2).
If a letter is entered in (2) that is not a valid letter grade an error should be displayed. This error handling should be done via the default case of your switch statement. Valid letter grades are: A, a, B, b, C, c, D, d, F, and f.
Grade | Range |
---|---|
A | 90-100 |
B | 80-89.99 |
C | 70-79.99 |
D | 60-69.99 |
F | 0-59.99 |
Your program should work for upper or lower case grades. See the example output for examples and formatting.
An example of an interaction with your program is shown below. When interacted with, your program must produce the exact same results.
Alexs-iMac:lab3b alex$ g++ -Wall -pedantic -Werror main.cpp Alexs-iMac:lab3b alex$ ./a.out Enter a letter grade **a Grade range is 90 – 100
Alexs-iMac:lab3b alex$ ./a.out Enter a letter grade **B Grade range is 80 - 89.99
Alexs-iMac:lab3b alex$ ./a.out Enter a letter grade **C Grade range is 70 - 79.99
Alexs-iMac:lab3b alex$ ./a.out Enter a letter grade **d Grade range is 60 - 69.99
Alexs-iMac:lab3b alex$ ./a.out Enter a letter grade **f Grade range is 0 - 59.99
Alexs-iMac:lab3b alex$ ./a.out Enter a letter grade **e Error: ‘e’ is not a valid letter grade
Save: Save your code as main.cpp
. Do not ignore this step or save your file(s) with different names.
Submit: Your program source code must be submitted via CodeGrade as a properly named .cpp
file prior to the deadline to receive full credit. Any submissions after the deadline will be subject to the class’ late policy.