When ever I try to run this program Eclipse immediately crashes

I tried double checking for infinite loops but I can't seem to figure it out. Please help?

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
 
#include <string>
#include <sstream>
#include <iostream>
using namespace std;
int Snum;
int testScore=0;
struct student{
	string name;
	int idnum;
	int quizAverage;
	string grade;
};
int main() {
	cout<<"How many students are there?";
	cin>>Snum;
	for (int t = 0; t<Snum; t++){
		student s[t];
		cout<<"What is the name of the student";
		getline (cin,s[t].name);
		cout<<"What is their Id number?";
		cin>> s[t].idnum;
			for (int b = 0; b>5; b++){

				cout<<"Please a enter a new test score";
				cin>>testScore;
				s[t].quizAverage = testScore + s[t].quizAverage;
									}
			s[t].quizAverage= s[t].quizAverage/5;
			testScore = 0;
				if (s[t].quizAverage >= 90){
					s[t].grade = "A";
				}
				else if (80<= s[t].quizAverage && s[t].quizAverage < 90){
					s[t].grade = "B";
				}
				else if (70<= s[t].quizAverage && s[t].quizAverage <80){
									s[t].grade = "C";
								}
				else if (60<= s[t].quizAverage && s[t].quizAverage <70){
									s[t].grade = "D";
								}
				else if (s[t].quizAverage <60){
									s[t].grade = "F";
								}

					return 0;

								}
			}
You have a bunch of errors.
And your indentation is insane.

The array s needs to be created before the loop and needs to be of size Snum. (I'll ignore that it's a VLA which are not part of standard C++.)

You're probably going to have some newline woes since you are mixing >> and getline.

quizAverage should probably be a floating point value (double).

See anything wrong here?for (int b = 0; b>5; b++)

The "return 0" should be outside of the loop (just before the very final brace).
You don't have an infinite loop. The program simply crashs.
The origin of the crash is basically line 18. You don't need to create an array. So remove [t] everywhere.

If you want for whatever reason to keep line 18 it needs to be

student s[t + 1]; // Note + 1

otherwise using t as an index would be out of bounds. Arrays in c[++] starts with 0.
it is not legal to make a run-time array. Some compilers will do it, but its not strictly legal.

so student s[t] where t is not a constant is illegal.
also I think
student s[0] is not allowed, or problematic, and your loop does that, so even a tolerant compiler of the above issue may choke on this one.

you have global variables. These cause problems, try to write it without that.


Topic archived. No new replies allowed.