question about switch

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
void takeClass(int numUnits, char grade);
{
	switch(grade)
	{
	case 'A':
			students.gradePointsEarned = students.gradePointsEarned + (unitsTaken * 4);
			break;
	case 'B':
			students.gradePointsEarned = students.gradePointsEarned + (unitsTaken * 3);
			break;		
	case 'C':
			students.gradePointsEarned = students.gradePointsEarned + (unitsTaken * 2);
			break;
	case 'D':
			students.gradePointsEarned = students.gradePointsEarned + (unitsTaken * 1);
			break;		
	case 'F':
			students.gradePointsEarned = students.gradePointsEarned + (unitsTaken * 0);
			break;
	default:
			cout << grade << " incorrect" << endl;
			return;
	}
	students.numUnits = students.numUnits + unitsTaken;
} 


sorry im a noob at c++ and i keep getting 1 error message when trying to run this and i cannot figure out why, any help would be great thanks
What does the error message say?
1>c:\documents and settings\fear\my documents\visual studio 2008\projects\homework 2 trying\homework 2 trying\homework 2 trying.cpp(55) : error C2447: '{' : missing function header (old-style formal list?)
You have a stray ';' after your function name/parameters.
if i take out the ';' after my function name i get like 12 error messages that say

1>c:\documents and settings\fear\my documents\visual studio 2008\projects\homework 2 trying\homework 2 trying\homework 2 trying.cpp(59) : error C2143: syntax error : missing ';' before '.'
The switch looks fine...it is probably some other code that is causing the issue. Post the code before this function.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
#include <string>
using namespace std;


class students 
{
private: 
	string firstName;
	string lastName;
	int unitsTaken;
	int gradePointsEarned;

public: 
	students();
	~students();
	void takeclass(int numUnits, char grade);
	
		
		
		
	



};


int main ()
{

	students::students();
	
		

	





	return 0;
}



	students::students():  firstName("Unknown"), lastName ("Student"), unitsTaken ('0'), gradePointsEarned ('0')
	{
		cout << "We have a student with no name!" << endl;
	}	//constructor definitions.



		void takeClass(int numUnits, char grade)
{
	switch(grade)
	{
	case 'A':
			students.gradePointsEarned = students.gradePointsEarned + (unitsTaken * 4);
			break;
	case 'B':
			students.gradePointsEarned = students.gradePointsEarned + (unitsTaken * 3);
			break;		
	case 'C':
			students.gradePointsEarned = students.gradePointsEarned + (unitsTaken * 2);
			break;
	case 'D':
			students.gradePointsEarned = students.gradePointsEarned + (unitsTaken * 1);
			break;		
	case 'F':
			students.gradePointsEarned = students.gradePointsEarned + (unitsTaken * 0);
			break;
	default:
			cout << grade << " incorrect" << endl;
			return;
	}
	students.numUnits = students.numUnits + unitsTaken;
}



	students::~students()
	{
	
	}


thats my entire code
I think you are confused on how to make/use classes...try reading this:

http://www.cplusplus.com/doc/tutorial/classes/
Topic archived. No new replies allowed.