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;
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";
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?
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.