Exception throw will not execute?

Ok, I am trying to throw an exception if the user enters in 0 for their major, for some reason my exception will not execute if 0 is entered in for the major though. I cannot seem to figure it out, any ideas are appreciated, thanks in a advance.
Here is my code:

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
void getStudents(Student *students)
{	

	int index; //loop control
	
	//loop for info
	for(index = 0; index < 2; index++)
	{	

		//prompt user for name
		cout << "\n";
		cout << "Enter the name of student # " << (index + 1);
		cout << ":" << endl;
		cin.ignore();
		cin.getline(students[index].name, 30);
		

		//prompt user for major
		cout << "Enter the major for student # " << (index + 1);
		cout << ":" << endl;
		cin >> students[index].gpa;
		
		
		//prompt user for GPA
		cout << "Enter the GPA of student # " << (index + 1);
		cout << ":" << endl;
		cin >> students[index].major;
			
			//throw exception
			if(students[index].major == 0)
			{
				string exceptionString = "Bad Major, Major cannot be zero!\n";
				throw exceptionString;
			}
			else	
	
		cin.ignore();
	}

}


Part of my main()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
//try & catch
	try
	{
		getStudents(students);
	}
	catch(string exceptionString)
	{
		cout << exceptionString;
	}


	printStudents(students);

return 0;
Compare lines 19 and 21.

Compare lines 25 and 27.
Geez, im getting tired lol, Thanks for pointing that out @cire!
Last edited on
Topic archived. No new replies allowed.