Keep getting errors using the switch option

Hey everybody!

I'm trying to create this program for a school project, but I keep getting errors using the switch option in the code itself. Is there a reason why this happens? Here is the code:

#include <iostream>
#include <iomanip>

using namespace std;

int main()

{
char courseType = ' ';
char grade = ' ';
short studentId = 0;

//Enter Course Name and Student ID.

cout << "Enter Course Name: ";
cin >> courseType;
cout << "Enter Student ID Number(s): ";
cin >> studentId;
studentId = toupper(studentId);

switch (studentId);
{
case 1234:
cout << "Student Grade is: 87";
break;

case 2345:
cout << "Student Grade is: 76";
break;

case 3456:
cout << "Student Grade is: 45";
break;

case 4567:
cout << "Student Grade is: 89";
break;

case 5678:
cout << "Student Grade is: 103";
break;

case 6789:
cout << "Student Grade is: 83";
break;

case 7890:
cout << "Student Grade is: 72";
break;

case 8901:
cout << "Student Grade is: 57";
break;

case 9012:
cout << "Student Grade is: 95";
break;

case 0123:
cout << "Student Grade is: 98";
break;

default:
cout << "Invalid Student ID";
} //end switch

cout << endl;
system("pause");

// Enter the Number Grade.
cout << "Enter Number Grade: ";
cin >> grade;
grade = toupper(grade);

if (grade >= '89.5')
cout << "A";
else if (grade >= '84.5')
cout << "B+";
else if (grade >= '79.5')
cout << "B";
else if (grade >= '74.5')
cout << "C+";
else if (grade >= '69.5')
cout << "C";
else if (grade >= '64.5')
cout << "D+";
else if (grade >= '59.5)
cout << "D";
else if (grade <= '59.4)
cout << "F";
else //default
cout << "Invalid Grade";
//end if

cout << endl;
system("pause");
return 0;

}

I know I'm doing something worng, but I don't understand what it is. Please help me! I'll give you some cookies!
1
2
3
4
5
switch (studentId); // no semicolons here
{
case 1234:
...
} //end switch 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
if (grade >= '89.5')
cout << "A";
else if (grade >= '84.5')
cout << "B+";
else if (grade >= '79.5')
cout << "B";
else if (grade >= '74.5')
cout << "C+";
else if (grade >= '69.5')
cout << "C";
else if (grade >= '64.5')
cout << "D+";
else if (grade >= '59.5) // remember to end apostrophes
cout << "D";
else if (grade <= '59.4) // im not sure if apostrophe is correct word
cout << "F";
else //default
cout << "Invalid Grade";
//end if 


chars like that wont work anyway. '74.5' you cant check if something is bigger than that :P. those signs can only store 1 character like 'h'. so cin >> grade; will just store the first letter i think. just try storing the input in double and checking for numbers. if you want to store multiple letters use the quotation marks char smth[10] = "hello"; Looking forward to the cookies.
Last edited on
I keep getting errors...

That's not very specific, is it?

Delete the semikolon after switch(studentId).
Breadman - Thanks for the quick reply! I did what you said and it works. Thanks for everything :)
Topic archived. No new replies allowed.