### Help with math tutor 3 major issues left to solve.

hey guys I'm writing a math tutor program and i need it to
1.keep track of the number of correct scores as well as number tries and
2.i also want to have 5 answer options,and
3.also give the user up to 3 tries to get a question right.
i have the basis of the code but the others elude me.
I'm also trying to write this without any global variables. thanks.
here's what i have so far
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283`` ``````#include #include #include #include #include using namespace std; char Menu(); //prototypes void difficulty(int &); void generate(double &, double &, int ); void addition(double &, double, double); void subtraction(double &, double, double); void multiplication(double &, double, double); void division(double &, double, double, char); void Ans(double &); int main() { double correctans, num1, num2; char choice; char line[80]; int diff; time_t now = time(0); string name; srand(now); // Seed the random number generator. //cout << ctime(&now) << endl; cout << "what is your first and last name " << endl; getline(cin, name); for (unsigned i = 0; i < name.length(); i++) if (name[i] == ' ') name[i] = '_'; name += ".txt"; cout << endl << endl << endl; cout << "Welcome to the Math Skills Program " << endl; cout << "This program allows you to practice your math skills" << endl; cout << "Choose what to practice in the menu shown below." << endl; cout << endl << endl << endl; difficulty( diff); bool test = true; while (test) { now = time(0); // cout << endl << "Problem start time:" << ctime(&now) << endl; generate(num1, num2, diff); choice = Menu(); switch (choice) { case 'a': addition(correctans, num1, num2); break; case 'b': subtraction(correctans, num1, num2); break; case 'c': multiplication(correctans, num1, num2); break; case 'd': division(correctans, num1, num2, choice); break; case 'q': test = false;// The user chose to quit the program. cout << "Thank you for using Math Tutor program.\n\n"; return 0; break; } } if (choice != 'q') { cout << "incorect input please try again" << endl; cin >> choice; // Loop again } return 0; } char Menu() { char choice; { cout << "Arithmetic Practice program\n" << endl; // Display the menu and get a choice. //cout << "------------------------------\n"; cout << "---------------------------------------------------------" << endl; cout << "ARITHMETIC PRACTICE PROGRAM " << endl; cout << "MAIN MENU" << endl; cout << "-------------------------------------------------------- - " << endl; cout << "a. Addition \n"; cout << "b. Subtraction\n"; cout << "c. Multiplication\n"; cout << "d. Division\n"; cout << "q. Quit the program\n"; cout << "------------------------------\n"; cout << "Enter your choice (a b c d q): "; cin >> choice; } // Validate the choice. choice = tolower(choice); if (choice >= 'a' && choice <= 'd' || choice == 'q') cout << "You entered: '" << choice << "', your input is valid " << endl; else { cout << "The valid choices are a, b, c, " << "d, and q. Please choose: "; cin >> choice; } cout << endl; return choice; } void difficulty(int & diff) { //double studentans; char line[80]; cout << "Select diffculty. Please choose" << endl; cout << " 1 for 1 digit\n" << " 2 for 2 digits\n" << " 3 for 3 digits\n" << " 4 for 4 digits\n" << " 5 for 5 digits\n" << endl; cout << endl << "> "; cin >> line; diff = atoi(line); while (diff < 1 || diff >5) { cout << "Enter 1-5 only " << endl; cin >> line; diff = atoi(line); cin.clear(); cin.ignore(1000, '\n'); } } void generate( double & num1, double & num2, int diff) { int min, max; min = pow(10., diff - 1); max = pow(10., diff); num1 = min + rand() % (max - min); num2 = min + rand() % (max - min); } void Ans(double & correctans) { double studentans; // char choice; // if (choice >= 'a' && choice <= 'd') // { cin >> studentans; if (studentans == correctans) cout << "\n\nCongratulations! That's right.\n\n"; else cout << "\n\nSorry, the correct answer is " << correctans << ".\n\n"; // } } void addition(double & correctans, double num1, double num2) { double studentans; //Generate two random numbers in the range 1 - 500. cout << "Prepare to add" << endl; //difficulty(num1, num2); // num1 and num2 haven't been randomly generated yet correctans = num1 + num2; // Display the problem. cout << "\n\n"; cout << " " << setw(4) << num1 << endl; cout << " +" << setw(4) << num2 << endl; cout << " " << "----" << endl; cout << " "; Ans(correctans); } void subtraction(double & correctans, double num1, double num2) { double studentans; //difficulty(num1, num2); //if ('h' : num2 > num1) //num2 = 1 + rand() % 999; correctans = num1 - num2; // Display the problem. cout << "\n\n"; cout << " " << setw(8) << num1 << endl; cout << " -" << setw(8) << num2 << endl; cout << " " << "----" << endl; cout << " "; Ans(correctans); } void multiplication(double & correctans, double num1, double num2) { double studentans; //difficulty(num1, num2); correctans = num1 * num2; cout << "\n\n"; cout << " " << setw(4) << num1 << endl; cout << " *" << setw(4) << num2 << endl; cout << " " << "----" << endl; cout << " "; Ans(correctans); } void division(double & correctans, double num1, double num2, char choice) { double studentans; num1 = num2 * num1; //difficulty(num1, num2); /*if (choice == 'b') { num2 = 1 + rand() % 9; num1 = num2 * (rand() % 50 + 1); } if (choice == 'm') { num2 = 1 + rand() % 20; num1 = num2 * (rand() % 100 + 1); } else if (choice == 'h') { num2 = 1 + rand() % 15; num1 = num2 * (rand() % 110 + 1); } */ // Calculate the correct answer. correctans= num1 / num2; cout << "\n\n"; cout << " " << num1 << " / " << num2 << " = "; Ans(correctans); }``````
Topic archived. No new replies allowed.