Hi, first time poster here, so I hope everything I post and type goes well. Anyway here goes...
Okay, I'm writing a program that will randomly generate a math problem, ask the user to enter an answer, if they get it right, it gives them one of four randomly generated positive responses. If they get it wrong, they are given one of four randomly generated negative responses, and are then asked to try again two more times, upon two more failures they are given the answer. Finally, whether they get it right or wrong, the user is asked if they want another math problem or not, if yes, another is randomly generated. If no, they are told how many they got correct and how many they got wrong.
So here's the code I have written so far:
I realize it's very rough around the edges, but I've hit a wall and my mind is fried over this program. Any comments, tips, or help would be greatly appreciated. And hopefully one day I will be able to return the favor and help you out as well. Thanks again.Code:#include <iostream> #include <string> using namespace std; void greeting (); int goodresponses (); int badresponses (); int x = rand() %9 + 1; int y = rand() %9 + 1; int arithmetic (int x, int y); int ctr=1; int guess; char decision; int answer1= x + y; int answer2= x - y; int answer3= x * y; int answer4= (x * y)/x; int main () { srand (time(0)); greeting (); int arithmetic = rand() % 4 + 1; if (arithmetic == 1) { cout << "What is " << x << " + " << y << "?" << endl; } else if (arithmetic == 2) { cout << "What is " << x << " - " <<y << "?" << endl; } else if (arithmetic == 3) { cout << "What is " << x << " * " << y << "?" << endl; } else if (arithmetic == 4) { cout << "What is " << x*y << " / " << x << "?" << endl; } cin >> guess; if (guess == answer1){ cout << goodresponses() << endl; } else if (guess == answer2){ cout << goodresponses() << endl; } else if (guess == answer3){ cout << goodresponses() << endl; } else if (guess == answer4){ cout << goodresponses() << endl; } else { cout << badresponses() << endl; } while (ctr<=3 && guess != answer1||answer2||answer3||answer4){ cin >> guess; ctr++; } return 0; } void greeting () { cout << "***Welcome to Math-o-matic!***" << endl; } int goodresponses () { int goodresponses = rand() % 4 + 1; if (goodresponses == 1) { cout << "Very good!" << endl; } else if (goodresponses == 2) { cout << "Excellent!" << endl; } else if (goodresponses == 3) { cout << "Nice work!" << endl; } else if (goodresponses == 4) { cout << "Way to go!" << endl; } } int badresponses () { int badresponses = rand() % 4 + 1; if (badresponses == 1) { cout << "No. Please try again." << endl; } else if (badresponses == 2) { cout << "Wrong. Try Again." << endl; } else if (badresponses == 3) { cout << "Don't give up!" << endl; } else if (badresponses == 4) { cout << "No. Keep trying." << endl; } else if (badresponses == 4) { cout << "No. Keep trying." << endl; } }