Hello everyone, I'm attempting to teach myself C++ and I've started to create a custom GPA calculator using the principles I've learned so far (although I'm sure there are easier ways to do it). My code compiles and asks the first two questions as expected (one at a time) but upon answering the second question (What is your grade in class 1?) All of the next 4 questions appear in a run-on statement and windows tells me the .exe file has stopped working without explanation.
If there is a simple fix I am all ears, but if I'm in way over my head I'll scrap the whole thing, as I'm only experimenting and trying to learn more. Again, there is no error because the program compiles fine via CodeBlocks and the GNU compiler, Thanks everybody!
float A = 4.0;
float Am= 3.7;
float Bp = 3.3;
float B = 3.0;
float Bm = 2.7;
float Cp = 2.3;
float C = 2.0;
float Cm = 1.7;
float Dp = 1.3;
float D = 1.0;
float F = 0.0;
int main ()
cout << "How many classes do you take? Indicate pluses and minuses with a lower case p or m, so a B+ would be written Bp ";
cout << "What was your grade in class 1? ";
cout << "What was your grade in class 2? ";
cout << "What was your grade in class 3? ";
cout << "What was your grade in class 4? ";
cout <<"What was your grade in class 5? ";
cout <<"What was your grade in class 6? ";
cout << "Your GPA is: " << classes / (class1 + class2 + class3 + class4 + class5 + class6) << endl;
windows tells me the .exe file has stopped working
This doesn't sound like a "Console Closing Before Output" problem.
You're putting cin into a fail state when you try to read "Ap" or something similar into an int. The program then blows right past all your other cins, leaving you with no data in class1, class2, etc. It looks like your runtime environment is configured in debug mode, so these probably happen to be initialized to zero for you (even though you should be doing this yourself). Then, what happens on line 48 when you perform division you attempt to divide by zero.
You'll have to get strings from the user and turn them into values before you add them, or get actual integers from the user instead of "A", "Bp", "Cm", etc.