Looping Grade Program Challenge: Will not loop properly

Hello, I have a problem with a C++ programming assignment that I need to get done by next Monday, and it's driving me crazy.

The premise behind the program is not exactly the greatest feat of programming.
This program is supposed to:
* Take a numerical grade input from the user
* Tell the user what grade they got.
- If the user got 100, they will be informed they have a perfect score.
- If the user got over 100, they will be informed that they got extra credit on top of their perfect score
- If the user inputs a negative grade or text characters, they will recieve an error message.
* After these, they will be asked if they want to enter another grade
- If yes, the program will go back to the grade input section.
- If no, the program will output a "thank you" message and exit the program.

However when it goes back to the grade input section, it does NOT let the user input another grade, instead it loops over and over as if the same grade is being entered. Note that they're have been multiple incarnations of this program, none of which have solved: I tried clearing the string value and the compiler won't recognize the command (erase). I changed the original from integer inputs to string inputs, which came colsest to making a functional build, but still no dice. Changing the loop types doesn't work. Changing the subsystem of the linker (windows/console) doesn't work. NOTHING works.

I'm pressed for time so I cannot provide more details. If anyone has a solution, please post it. Here is the source code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Challenge 1

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

	
float main () // data type set to float to handle decimal values
{
	float g; // grade value
	bool d = true; // determiner
	string e; // declaring string
	int response;
	cout << "GRADING PROGRAM";
	loop:
	cout << "\nPlease enter your numeric score:";
	getline (cin, e);
	stringstream(e) >> g; // coverts content of string to grade value
	do {
		if (g > 100){
		cout << "Wow, you got an A and earned extra credit on top of it! Amazing! Shall we go the nonstandard route and call this an 'S' grade?\n"; 
	}
	else if (g == 100){
		cout << "A perfect 100! Congratulations! You earned an A.\n";
	}
	else if (g < 100, g >= 90) {
		cout << "Great job! You earned an A.\n";
	}
	else if (g < 90, g >= 80) {
		cout << "Good! You earned a B.\n";
	}
	else if (g < 80, g >= 70) {
		cout << "You've earned a C. Not bad, could be better...\n";
	}
	else if (g < 70, g >= 60) {
		cout << "You've earned a D. Surely you can do better!\n";
	}
	else if (g < 60, g >= 0) {
		cout << "You've earned an F! You're failing -- you need to get your grade up!\n";
	}
	else {
		cout << "ERROR: Invalid grade value entered.\n";
	}
	cout << "Would you like to enter another grade? 1 for yes, 2 for no\n";
	cin >> response;
	switch (response) { // checks for response value
  case 1:
    d = true;
	e& erase();
    break;
  case 2:
    d = false; // chanfe
    break;
  default:
	  cout << "ERROR: Invalid response\n";} 
	goto loop;} // 
	while (d == true);
	cout << "Thank you for using my grading program.\n";
	return 0;
}
Maybe try clearing the input buffer? Use cin.ignore(80,"\n") to clear up to 80 characters in the input buffer after your input command.
Flatly and simply, we don't post solutions on this website. We post explanations and clarifications. We provide help, not answers.
Now then, why is main returning float? Why not return int?
Don't use goto either. That's horrendous. You could wrap it in a loop easily.
It's difficult to say what the issue is because all the indenting is off.
Why are you using a string for the input? It should be an integer. Then you can stop using getline, because getline accepts an enter character. When you cin>>response, you press enter to send the input, leaving the \n in the buffer. The \n is then taken by the getline. So rather than wasting your time with a string and its stringstream, just cin an integer. You may want to, as the last poster noted, ignore between cins to prevent the additional newlines from hanging around.
I would say the worst issue with this is "float main" instead of int.

Main must return int. How could that be any clearer? If main returns anything but an integer, the program is completely invalid IMO, and is not worth reading.
float main is a travesty, but what about the pointless use of goto? I'd say that's worse, especially when the workaround is so obvious.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
while(true) {
    cout << "\nPlease enter your numeric score: ";
    cin >> g;

    /*if else grade here
     ...
    */
    
    cout << "Would you like to enter another grade? 1 for yes, 2 for no: ";
    cin >> response;
    
    if(response==1)
        continue;
    else if(response==2) {
        cout << "Thank you for using my grading program.\n";
        break;
    } else {
        cout << "WTF!.\n";
        break;
    }
}


and change main to int..

one more thing.. read more.. http://cplusplus.com/doc/tutorial/control/
Topic archived. No new replies allowed.