Same code with tags. Thanks

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

#include <iostream>
#include <string>
using namespace std;

Struct studenttype{
	string firstname;
	string lastname;
	unsigned studentnumber;
	unsigned numberofunits;
	unsigned gradepoints;
};

void output(const studenttype & student_info);
void takeclass(studenttype & student, int unitstaken, char grade);


int main (){
	studenttype studentone = {"John", "Smith", 123456789, 0, 0 };
	studenttype studenttwo = {"Mary", "Jones", 123456790, 6, 24};

	output(studentone);
	output(studenttwo);

	takeclass(studentone, 3, 'A');
	takeclass(studenttwo, 4, 'B');
}

void output(const studenttype & student_info){
	cout << student_info.firstname << student_info.lastname << ", #" << student_info.studentnumber << ":  " << student_info.numberofunits
	<< " units and " << student_info.gradepoints << " grade points" <<endl;
}

void takeclass(studenttype & student, int unitstaken, char grade){   
	switch(grade)
	{
	case 'A':
			student.gradepoints = student.gradepoints + (unitstaken * 4);
			break;
	case 'B':
			student.gradepoints = student.gradepoints + (unitstaken * 3);
			break;		
	case 'C':
			student.gradepoints = student.gradepoints + (unitstaken * 2);
			break;
	case 'D':
			student.gradepoints = student.gradepoints + (unitstaken * 1);
			break;		
	case 'F':
			student.gradepoints = student.gradepoints + (unitstaken * 0);
			break;
	default:
			count << grade << " is not a valid letter grade" << endl;
			return;
	}
	student.numberofunits = student.numberofunits + unitstaken;
}


lol hilarious. So you went ahead and created a new post just to stick your code in the code tags per chrisnames advice here? http://www.cplusplus.com/forum/general/14184/ You should have just edited your post!!
Read jsmith's post in the above link.

Funnily, like this:
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
#include <iostream>
#include <string>
using namespace std;

struct studenttype{
	string firstname;
	string lastname;
	unsigned studentnumber;
	unsigned numberofunits;
	unsigned gradepoints;
};

void output(const studenttype& student_info);
void takeclass(studenttype& student, int unitstaken, char grade);


int main (){
	studenttype studentone = {"John", "Smith", 123456789, 0, 0 };
	studenttype studenttwo = {"Mary", "Jones", 123456790, 6, 24};

	output(studentone);
	output(studenttwo);

	takeclass(studentone, 3, 'A');
	takeclass(studenttwo, 4, 'B');
}

void output(const studenttype& student_info){
	cout << student_info.firstname << student_info.lastname << ", #" << student_info.studentnumber << ":  " << student_info.numberofunits
	<< " units and " << student_info.gradepoints << " grade points" <<endl;
}

void takeclass(studenttype& student, int unitstaken, char grade){
	switch(grade)
	{
	case 'A':
			student.gradepoints = student.gradepoints + (unitstaken * 4);
			break;
	case 'B':
			student.gradepoints = student.gradepoints + (unitstaken * 3);
			break;
	case 'C':
			student.gradepoints = student.gradepoints + (unitstaken * 2);
			break;
	case 'D':
			student.gradepoints = student.gradepoints + (unitstaken * 1);
			break;
	case 'F':
			student.gradepoints = student.gradepoints + (unitstaken * 0);
			break;
	default:
			cout << grade << " is not a valid letter grade" << endl;
			return;
	}
	student.numberofunits = student.numberofunits + unitstaken;
}


It works. By the way, 4 != 50.
You capitalized "struct", you were using bitwise & on studenttype x twice and you also put "count" instead of cout.
Last edited on
i got 43 errors to be exact when I compiled using Visual C++.
When I compiled using GCC I got 4. Funny that...
Last edited on
gcc? i like that better already. where is that? i got the visual C++ express form microsoft's website.
http://gcc.gnu.org/
GCC stands for the GNU Compiler Collection or it can stand for the GNU C Compiler.
Topic archived. No new replies allowed.