The issue is in the for loop with "class." Anywhere there is class. At first I assumed I just needed to declare class as an int instead of within the loop, but that didn't work either. I just need the program to enter course name, course number, grade, and credit hours and calculate GPA. And it needs to be an arbitrary number of classes hence the for loop. But I can't make it work. Any suggestions?
Thanks in advance!
#include <iostream>
using namespace std;
int main( )
{
int numClasses;
double total, GPA;
cout << "This program will help you calculate your GPA. \n";
cout << "How many classes did you take this semester? ";
cin >> numClasses;
for (int class = 1; class <= numClasses; class++)
total = 0;
{
char coursename, coursenum, grade;
float hours, ngrade;
cout << "Please enter the name, course number, the grade you received, \n";
cout << "and the amount of credit hours " << class << " is worth. \n";
cout << "Please separate each entry by pressing enter. ";
cin >> coursename;
cin >> coursenum;
cin >> grade;
cin >> hours;
class is a reserved word in C++. Use some other variable name.
Note: Only the assignment of 0 to total is within the scope of your loop.
PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.