When I enter different numbers in "studentNumber" and "testNumber" variables, the code closes at a specific place. No matter what value I give to the variables, the code stands in the second exam part of the 1st student.
Code terminates with this error "Process returned -1073741819 (0xC0000005) execution time: 11.105 s"
#include <iostream>
using namespace std;
int studentNumber=0;
int testNumber=0;
struct Student
{
string name,grade;
int studentNo,*testResults;
double average;
};
void getValue()
{
cout << "Enter the number of students: ";
cin >> studentNumber;
Student Students[studentNumber];
cout << "Enter the number of tests: ";
cin >> testNumber;
int Arr[testNumber];
Students[0].testResults = Arr;
for(int i=1; i<=studentNumber; i++)
{
cout<< "\n" << "Enter the name of the " << i << ". student: ";
cin >> Students[i].name;
cout<< "\n" << "Enter the number of the " << i << ". student: ";
cin >> Students[i].studentNo;
for(int z=0; z<testNumber; z++)
{
cout<< "\n" << "Enter the " << z+1 << ". exam grade of the " << i << ". student: " ;
cin >> Students[i].testResults[z];
}
}
}
int main()
{
getValue();
}
result: