new to c++ i need some help cant figure this out

so i have a project due tomorrow this is exactly what it wants from me

"Write a program which is used to calculate the GPA based on the grades for different courses input by user. User should be able to use this to enter grades for as many courses as he wants unless he wants to quit. (you may consider using some loop). Once user has completed entering of data, the program should be able to provide a feedback to the user about the GPA. A is equal to 4, B is equal to 3, C is equal to 2, D is equal to 1, rest are 0. Use minimum 5 course to demonstrate working of your code. "

this is what i have so far doesnt seem to work the way i want it to

#include <iostream>
#include <string>

using namespace std;

double GPA=0.0;
int grade;
char coursename [20];

int main ()
{
cout << " would you like to calculat you GPA ? enter a grade if so or enter Exit to quit"<<endl;
ask:
cin >> grade;
cout << " enter your course name ? ";
cin >> coursename;
cout << " your gpa is " << GPA << endl;





bool fterminate = false;
bool repeat = true;
do{



switch(grade)
{
case 'exit':
case 'Exit':
fterminate = false;
break;

case 'A':
case 'a':
GPA = 4.0;
repeat = false;
break;
case 'B':
case 'b':
GPA = 3.0;
repeat = false;
break;
case 'C':
case 'c':
GPA = 2.00;
repeat = false;
break;
case 'D':
case 'd':
GPA = 1.00;
repeat = false;
break;
case 'F':
case 'f':
GPA = 0.00;
repeat = false;
break;
case 'Yes':
case 'yes':
goto ask;
}

} while (grade != 'yes'|| grade != 'Yes');
while ( (!fterminate) );



}
Last edited on
'exit' should be "exit" aaaand switch case only can be use with number and letter not stirng
Last edited on
There is a... lot wrong with this code. Even if it did work, it isn't even solving the question- it just converts letter grades to numbers. It doesn't generate a full GPA- it just gives you the class grade per class. So, I will give you a few tips as to how to fix this:

1) Never use goto.

2) Never use goto.

3) There is no need to use c-style character arrays in a C++ program, especially when you #include the string header and never actually use it.

4) If a while statement isn't part of a do-while, and you end it with a semicolon, it will either never run or never end.

5) Your do-while loop is useless because of that god-awful goto statement thrown in the middle of the switch statement.

6) How would the user know to type in "yes" when you never tell them to?

7) Try not to use global variables. In this program especially, there's no need.

8) The variable grade is an integer, and you compare it to both characters and strings.

9) "repeat" is never used.

Honestly, my suggestion would be to look over your notes, re-write the code from scratch, and see if it works. As for the project proper... well, I'll do my best to help you find your way through it. Just don't expect me to give you the solution code.
thanks so much i appreciate it this is my first year in c++ and i am struggling alot
ill do my best and post back my progress
Topic archived. No new replies allowed.