Hello everyone...

I have a problem on the last part of my codes.
This programm supposed to accept several kind of courses and its corresponding grades.
So far so good... but when it comes to display the courses and the grades and its remarks of passed or failed, the programm gives me an error message. Actually it gives me 45 errors beginning with the first if else statement.

Here are my codes so far:

#include <iostream>
#include <string>

using namespace std;

main()
{
	
	string name, course[10], grade[10];
	int x, y, n;
	char response;
	
	
	
	
	cout<< "Please enter your name: ";
	cin>> name;
	cout<< "Please enter number of subjects: ";
	cin>> y;
	cout<< "Hello " << name << " you have " << y << " subjects." << endl;
	

	n=1;



    for(int a=1; a<=y; a++)
{
	cout<< "Please enter your course " << n << ":";
	cin>> course[x];
	cout<< endl;
	cout<< "Please enter your Grade: ";
	cin>> grade[x];
	cout<< endl;
	n++;		
}			
			
	cout<< "Course   Grade   Remarks  " << endl;

		  for(int ctr=1;ctr<=y;ctr++)
{
		
		  if (grade[ctr] < 75)  // HERE THE FIRST ERROR STARTS
			    cout<< course[x]<< "5.0\t FAILED";
		
		  else if (grade[ctr] ==75)
				cout<< course[x]<< "\t3.0\t passed";
		
		  else if (grade[ctr] <=78)
				cout<< course[x]<< "\t2.75\t passed";

	      else if (grade[ctr] =81)
				cout<< course[x]<< "\t2.5\t passed";
		
		  else if (grade[ctr] <=84)
				cout<< course[x]<< "\t2.25\t passed";
		
		  else if (grade[ctr] <=87)
				cout<< course[x]<< "\t2.0\t passed";
		
		  else if (grade[ctr] <=90)
				cout<< course[x]<< "\t1.75\t passed";
		
		  else if (grade[ctr] <=93)
					cout<< course[x]<< "\t1.5\t passed";
		
		  else if (grade[ctr] <=96)
				cout<< course[x]<< "\t1.25 \t passed";
		
		  else if (grade[ctr] ==100)
				cout<< course[x]<< "\t1.0\t passed";

			else 
			cout<<"invalid input of grade";
}	
	cin>> response;

return 0;

}

If i set the if else statements in a comment block the programm runs ecxept the aoutput of course grade and remarks (pass/Failed).

Would be grate if somebody can help me out.

ups some spelling misstakes... never mind them :)

grade[] is an array of strings, it should be ints or doubles

hmmm... when i set grades as an integer then the compiler itself gives me this error mesage:

unhendlled exception in schule.exe: 0xC000005 Access violation.

so it will not run at all :(

Well your cins and couts are using a variable X which is never changed in your program. You should use the loop variable as your index.

for(int a=1; a<=y; a++)
{
cout<< "Please enter your course " << n << ":";
cin>> course[a];
cout<< endl;
cout<< "Please enter your Grade: ";
cin>> grade[a];
cout<< endl;
n++;
}

Also note that arrays start at zero.

#include <iostream>
#include <string>

using namespace std;

main()


{
	
	string name, course[10], grade[10];
	int x, y, n, g;
	char response;
	
	
	
	
	cout<< "Please enter your name: ";
	cin>> name;
	cout<< "Please enter number of subjects: ";
	cin>> y;
	cout<< "Hello " << name << " you have " << y << " subjects." << endl;
	

	n=1;



    for(int a=1; a<=y; a++)
{
	cout<< "Please enter your course " << n << ":";
	cin>> course[x];
	cout<< endl;
	cout<< "Please enter your Grade: ";
	cin>> g;
	cout<< endl;
	n++;		
}			
			
	cout<< "Course   Grade   Remarks  " << endl;

		  for(int ctr=1;ctr<=y;ctr++)
{
		
		  if (grade[ctr] < 75)
			    cout<< course[ctr]<< "5.0\t FAILED";
		
		  else if (grade[ctr] ==75)
				cout<< course[ctr]<< "\t3.0\t passed";
		
		  else if (grade[ctr] <=78)
				cout<< course[ctr]<< "\t2.75\t passed";

	      else if (grade[ctr] =81)
				cout<< course[ctr]<< "\t2.5\t passed";
		
		  else if (grade[ctr] <=84)
				cout<< course[ctr]<< "\t2.25\t passed";
		
		  else if (grade[ctr] <=87)
				cout<< course[ctr]<< "\t2.0\t passed";
		
		  else if (grade[ctr] <=90)
				cout<< course[ctr]<< "\t1.75\t passed";
		
		  else if (grade[ctr] <=93)
					cout<< course[ctr]<< "\t1.5\t passed";
		
		  else if (grade[ctr] <=96)
				cout<< course[ctr]<< "\t1.25 \t passed";
		
		  else if (grade[ctr] ==100)
				cout<< course[ctr]<< "\t1.0\t passed";

			else 
			cout<<"invalid input of grade";
}	
	cin>> response;

return 0;

}

i changed it to this now it changes right? But my compiler will hang itself up when i try to run this.

Sry im still new in c++

i changed the 1 to 0 but still a problem

It needs to be int grade[10]; it can't be string if you are going to do calculations with it. If you only have one g you're writing over it each time. And that course[x] should be course[a]

#include <iostream>
#include <string>

using namespace std;

main()


{
	
	string name, course[10], grade[10];
	int x, y, n;
	char response;
	
	
	
	
	cout<< "Please enter your name: ";
	cin>> name;
	cout<< "Please enter number of subjects: ";
	cin>> y;
	cout<< "Hello " << name << " you have " << y << " subjects." << endl;
	

	n=1;



    for(int a=0 a<=y; a++)
{
	cout<< "Please enter your course " << n << ":";
	cin>> course[x];
	cout<< endl;
	cout<< "Please enter your Grade: ";
	cin>> grade[x];
	cout<< endl;
	n++;		
}			
			
	cout<< "Course   Grade   Remarks  " << endl;

		  for(int ctr=1;ctr<=y;ctr++)
{
		
		  if (grade[ctr] < 75)
			    cout<< course[ctr]<< "5.0\t FAILED";
		
		  else if (grade[ctr] ==75)
				cout<< course[ctr]<< "\t3.0\t passed";
		
		  else if (grade[ctr] <=78)
				cout<< course[ctr]<< "\t2.75\t passed";

	      else if (grade[ctr] =81)
				cout<< course[ctr]<< "\t2.5\t passed";
		
		  else if (grade[ctr] <=84)
				cout<< course[ctr]<< "\t2.25\t passed";
		
		  else if (grade[ctr] <=87)
				cout<< course[ctr]<< "\t2.0\t passed";
		
		  else if (grade[ctr] <=90)
				cout<< course[ctr]<< "\t1.75\t passed";
		
		  else if (grade[ctr] <=93)
					cout<< course[ctr]<< "\t1.5\t passed";
		
		  else if (grade[ctr] <=96)
				cout<< course[ctr]<< "\t1.25 \t passed";
		
		  else if (grade[ctr] ==100)
				cout<< course[ctr]<< "\t1.0\t passed";

			else 
			cout<<"invalid input of grade";
}	
	cin>> response;

return 0;

}

these are my changes now... but compiler will hang itself up

it has to be for(int variable = 0;variable<number;variable++) that way you go from 0 to the number-1 element of the array (as a a[4] has a[0], a[1], a[2], and a[3]

#include <iostream>
#include <string>

using namespace std;

main()
{
	
	string name, course[10];
	int x, y, n, grade[10];
	char response;
	
	
	
	
	cout<< "Please enter your name: ";
	cin>> name;
	cout<< "Please enter number of subjects: ";
	cin>> y;
	cout<< "Hello " << name << " you have " << y << " subjects." << endl;
	

	n=1;



    for(int a=0; a<=y; a++)
{
	cout<< "Please enter your course " << n << ":";
	cin>> course[a];
	cout<< endl;
	cout<< "Please enter your Grade: ";
	cin>> grade[x];
	cout<< endl;
	n++;		
}			
			
	cout<< "Course   Grade   Remarks  " << endl;

		  for(int ctr=1;ctr<=y;ctr++)
{
		
		  if (grade[ctr] < 75)
			    cout<< course[ctr]<< "5.0\t FAILED";
		
		  else if (grade[ctr] ==75)
				cout<< course[ctr]<< "\t3.0\t passed";
		
		  else if (grade[ctr] <=78)
				cout<< course[ctr]<< "\t2.75\t passed";

	      else if (grade[ctr] =81)
				cout<< course[ctr]<< "\t2.5\t passed";
		
		  else if (grade[ctr] <=84)
				cout<< course[ctr]<< "\t2.25\t passed";
		
		  else if (grade[ctr] <=87)
				cout<< course[ctr]<< "\t2.0\t passed";
		
		  else if (grade[ctr] <=90)
				cout<< course[ctr]<< "\t1.75\t passed";
		
		  else if (grade[ctr] <=93)
					cout<< course[ctr]<< "\t1.5\t passed";
		
		  else if (grade[ctr] <=96)
				cout<< course[ctr]<< "\t1.25 \t passed";
		
		  else if (grade[ctr] ==100)
				cout<< course[ctr]<< "\t1.0\t passed";

			else 
			cout<<"invalid input of grade";
}	
	cin>> response;

return 0;

}

ok made all the changes but here again the error is again:

unhendlled exception in schule.exe: 0xC000005 Access violation.

But thanks for the help... yes there were some stupid errors :)

actually it runs but half way the during my inputs for course and grade i will receive this error:

unhendlled exception in schule.exe: 0xC000005 Access violation.

I think its maybe from the compiler itself and has nothing to do with the code?

#include <iostream>
#include <string>

using namespace std;

main()


{
	
	string name, course[10];
	int x, y, n, grade[10];
	char response;
	
	
	
	
	cout<< "Please enter your name: ";
	cin>> name;
	cout<< "Please enter number of subjects: ";
	cin>> y;
	cout<< "Hello " << name << " you have " << y << " subjects." << endl;
	

	n=1;



    for(int a=0; a<=y; a++)
{
	cout<< "Please enter your course " << n << ":";
	cin>> course[a];
	cout<< endl;
	cout<< "Please enter your Grade: ";
	cin>> grade[x];
	cout<< endl;
	n++;		
}			
			
	cout<< "Course   Grade   Remarks  " << endl;

		  for(int ctr=1;ctr<=y;ctr++)
{
		
		  if (grade[ctr] < 75)
			    cout<< course[ctr]<< "5.0\t FAILED";
		
		  else if (grade[ctr] ==75)
				cout<< course[ctr]<< "\t3.0\t passed";
		
		  else if (grade[ctr] <=78)
				cout<< course[ctr]<< "\t2.75\t passed";

	      else if (grade[ctr] =81)
				cout<< course[ctr]<< "\t2.5\t passed";
		
		  else if (grade[ctr] <=84)
				cout<< course[ctr]<< "\t2.25\t passed";
		
		  else if (grade[ctr] <=87)
				cout<< course[ctr]<< "\t2.0\t passed";
		
		  else if (grade[ctr] <=90)
				cout<< course[ctr]<< "\t1.75\t passed";
		
		  else if (grade[ctr] <=93)
					cout<< course[ctr]<< "\t1.5\t passed";
		
		  else if (grade[ctr] <=96)
				cout<< course[ctr]<< "\t1.25 \t passed";
		
		  else if (grade[ctr] ==100)
				cout<< course[ctr]<< "\t1.0\t passed";

			else 
			cout<<"invalid input of grade";
}	
	cin>> response;

return 0;

}

i changed the ctr to 0. But still the strange error message is coming.

Still have the grade[x] in there... take the x out of your variable declarations so you can't use it by mistake.

if the index is zero it has to be a<y and ctr<y in your for conditions, and the program shouldn't go past your first entry of a grade due to the above. And no, it's not the compiler :)

Guys thank you so much i got it now

Thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you

Very welcome.

Please corret this:
else if (grade[ctr] =81)

Also if you add y greater then 10 (grade[10]) then the program fall apart.
Try with y=5(ok) and then with y=12 (error).

Please add there something like
if (y>10) cout<<"Too many courses, try again"<<endl;

commented: N/A -1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.