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;
}
|