Help with c++ grade calculator

Mar 8, 2012 at 9:55pm
Hello guys,
This is my first time posting on this forum and i hope i can get help.

I need to get the sum of the grades entered and take the sum, divide it by the number of courses to get the average. Please look at Z and X.

Thanks in advance.




Here is the code:

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

int main()
{
int students;
string name;
int id;
int grade ;
int z,x,y,g;
int numcourse;
string lettergrade;

stringstream summary;


cout << "\t--------------Welcome to the grade calculator----------------\n"<<endl;
cout << "Please Input the number of Students"<<endl;
cin >> students;

for (int i=0; i<students;i++){

cout<<"Student No. " <<i+1<<" please enter your name"<<endl;
cin>>name;

cout<<"Hello, " <<name<< endl;
cout<<"please enter your id"<<endl;
cin>>id;

cout << "Please Input the number of courses: " ;
cin >> numcourse;

for (int i=0; i<numcourse;i++){
int g;


cout << " Please input grade " << i+1<< endl;
cin>>g;


///////


z=(z+g);
x=(z/numcourse);

if(x>=90 && x<=100)
lettergrade = 'A';
else if(x>=80 && x <90)
lettergrade = 'B';
else if (x>=70 && x <80)
lettergrade = 'C';
else if (x>=60 && x <70)
lettergrade = 'D';
else if (x>=0 && x <60)
lettergrade = 'F';
}


cout<<"your average grade is: "<< x<< " Which is an " << lettergrade<<endl;
summary<<name <<id << "your average grade is: " << x << " Which is an " << lettergrade << "\n";

}


cout<<summary.str();;

system("pause");
return 0;


}
Mar 8, 2012 at 9:59pm
Interesting code.


..oh, did you have some problem you wanted help with? You need to be specific - what do you want help with?
Last edited on Mar 8, 2012 at 9:59pm
Mar 8, 2012 at 10:21pm
yea...I need to get the sum of the grades entered, take the sum and divide it by the number of courses to get the average.

grades = g



look at z and x, i gave it a try but its not working.
Last edited on Mar 8, 2012 at 10:23pm
Mar 8, 2012 at 10:42pm
Would you explain why you think it is not working?
Mar 8, 2012 at 10:46pm
I'm not really sure, if i can explain why it won't work i wouldn't be here.
Mar 8, 2012 at 10:47pm
I don't mean what code is causing it to not work, I mean what is happening that makes you say "it doesn't work"? Does it not compile? Does it crash? Does it output the my little pony song? What about it isn't working?
Mar 9, 2012 at 1:06am
ok...the problem that i'm facing is it is not calculating the sum of the grades correctly.
It calculates it right for the first user, but not for the second user (if more than 1 users is entered)
It adds the sum of the first user and the second user, and displays it for the second user.
Please look at the image.

[IMG]http://i41.tinypic.com/mr66b8.jpg[/IMG]
Last edited on Mar 9, 2012 at 1:08am
Topic archived. No new replies allowed.