Reference no: EM132254089
How do you add an additional switch statement? i tried multiple times and i'm not sure if i don't understand braces enough but it didn't seem doable. also, I'm not sure what the teacher wants me to submit. This the problem. I'm not sure my code is right or wrong. Please someone explain to me this step by step. I really need help!!
This lab lets students work with the switch statement.
- Remove the break statements from each of the cases. What is the effect on the execution of the program?
- Add an additional switch statement that allows for a Passing option for a grade of D or better. Use the sample run given below to model your output.
Sample Run: What grade did you earn in Programming I?
YOU PASSED! An A - excellent work!
The following is the code to be used:
// This program illustrates the use of the Switch statement.
// PLACE YOUR NAME HERE
#include <iostream>
using namespace std;
int main()
{
char grade;
cout << "What grade did you earn in Programming I ?" << endl;
cin >> grade;
switch( grade ) // This is where the switch statement begins
{
case 'A': cout << "an A - excellent work !" << endl;
break;
case 'B': cout << "you got a B - good job" << endl;
break;
case 'C': cout << "earning a C is satisfactory" << endl;
break;
case 'D': cout << "while D is passing, there is a problem" << endl;
break;
case 'F': cout << "you failed - better luck next time" << endl;
break;
default: cout << "You did not enter an A, B, C, D, or F" << endl;
}
return 0;
}
This is my code
#include <iostream>
using namespace std;
int main()
{
char grade;
cout << "What grade did you earn in Programming I ?" << endl;
cin >> grade;
switch( grade )
{
case 'A': cout << " You Passed! " << endl;
break;
case 'B': cout << " You got a B - Good Job! " << endl;
break;
case 'C': cout << " Earning a C is satisfactory" << endl;
break;
case 'D': cout << " while D is passing, there is a problem " << endl;
break;
case 'F': cout << " You failed " << endl;
break;
default: cout << "You did not enter an A, B, C, D, or F" << endl;
}
return 0;
}