I need to create a program where the user selects addition, subtraction, or multiplication, and when they select one, 2 random numbers appear, and they must put in the right answer. The problem is, i cant get the correct answer. It just says: Would you like to play again?
Code:#include <iostream> #include <cstdlib> #include <ctime> using namespace std; void displayHeader(); void problemType(); void calcRealAnswer(); bool goAgain(); int calculateRandomNumber(); int choice = 0; int userAnswer = 0; int realAnswer = 0; float randomNumber = 0; int main(){ srand((unsigned)time(0)); do { displayHeader(); problemType(); }while(goAgain()); system("cls"); cin.get(); cin.get(); return 0; } void displayHeader() { cout<<"Welcome to my math game program. Sit back and enjoy!!"<<endl; cout<<endl; } void problemType() { cout << "Enter the number for the problem type desired:" << endl; cout << "1. Addition" << endl; cout << "2. Subtraction" << endl; cout << "3. Multiplication" << endl; cout << "Enter choice: "; cin >> choice; if (choice==1){ cout << calculateRandomNumber(); cout << " + "; cout << calculateRandomNumber(); cout << " = "; cin >> userAnswer;} else if (choice==2){ cout << calculateRandomNumber(); cout << " - "; cout << calculateRandomNumber(); cout << " = "; cin >> userAnswer;} else if (choice==3){ cout << calculateRandomNumber(); cout << " * "; cout << calculateRandomNumber(); cout << " = "; cin >> userAnswer;} else{ cout << "Invalid answer. Please select a valid choice: "; cin >> choice; } } bool goAgain() { char answer; cout << "Would you like to play again? "; cin >> answer; system("cls"); while(answer != 'Y' && answer != 'N') { cout << "Invalid choice. Would you like to go again? "; cin >> answer; } cout << endl; if(answer == 'Y') return true; else return false; } int calculateRandomNumber(){ return (rand()%100) + 1; }