code to grade students

consider the following statements in which grade is a variable of a type char

1
2
  i need a code to complete my grading 
please help me complete it



#include <iostream>
#include <string>

using namespace std;


switch (grade)
{



case 'A';
cout << "The grade point is 4.0.";
break;

case 'B';
cout << "The grade point is 3.0.";
break;

case 'C';
cout << "The grade point is 2.0.";
break;

case 'D';
cout << "The grade point is 1.0.";
break;

case 'F';
cout << "The grade point is 0.0.";

default:
cout << "The grade is invalid.";
return 0;
}
A number of things are going on here. Firstly, I don't know if you're writing a function that calculates the grade or if this is supposed to go in main, but either way you can't have just a switch statement and call it done.

Secondly, case is followed by a colon :, not a semicolon ;.

Thirdly, you forgot a break at the end before default.

The general syntax for a switch statement is:
1
2
3
4
5
6
switch(variable)
{
    case 1:  (code); break;
    case 2:  (code); break;
    default:  (code);
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>

using namespace std;

int main()
{
    char grade = 'A';
    switch (grade)
    {
        case 'A':  cout << "The grade point is 4.0."; break;
        case 'B':  cout << "The grade point is 3.0."; break;
        case 'C':  cout << "The grade point is 2.0."; break;
        case 'D':  cout << "The grade point is 1.0."; break;
        case 'F':  cout << "The grade point is 0.0."; break;
        default:   cout << "The grade is invalid.";
    }
}
Last edited on
thanks it really helped
but here is the rest of the question
Topic archived. No new replies allowed.