#include<iostream>
#include<iomanip>
#include<cstdlib>
#include"formatNumber.h"
using namespace std;
int main()
{
int choice;
int num1, num2, num3, num4, num5, num6;
int problem;
unsigned seed = time(0);
srand(seed);
cout << "This program will help you learn addition, subtraction,\n";
cout << "multiplication, and division. Press any key to continue." << endl;
cin.get();
do
{
cout << "Choose which math you would like to work on." << endl;
cout << "--------------------------------------------" << endl;
cout << "1. Addition\n";
cout << "2. Subtraction\n";
cout << "3. Multiplication\n";
cout << "4. Quit program\n";
cout << endl;
cout << "Choose 1,2,3,or 4: ";
cin >> choice;
switch(choice)
{
case 1: problem = 0;
num1 = rand() % 11;
num2 = rand() % 11;
while (problem != 999)
{
cout << "How much is " << num1 << " plus " << num2 << " (999 to exit)? ";
cin >> problem;
if ( problem == 999 )
break;
if ( problem == (num1 + num2) )
{
switch(rand() % 4)
{
case 0: cout << "Very good!\n";
break;
case 1: cout << "Nice work!\n";
break;
case 2: cout << "Excellent!\n";
break;
case 3: cout << "Keep up the good work!\n";
break;
}
num1 = rand() % 11;
num2 = rand() % 11;
}
else
{
switch(rand() % 4)
{
case 0: cout << "No. Please try again\n";
break;
case 1: cout << "Sorry. That's not it\n";
break;
case 2: cout << "No. Don't give up\n";
break;
case 3: cout << "Not yet. Keep trying\n";
break;
cout << "How much is " << num1 << " plus " << num2 << "(999 to exit)? ";
cin >> problem;
}
}
}
break;
case 2: problem = 0;
num3 = rand() % 11;
num4 = rand() % 11;
while (problem != 999)
{
cout << "How much is " << num3 << " minus " << num4 << " (999 to exit)? ";
cin >> problem;
if ( problem == 999 )
break;
if ( problem == (num3 - num4) )
{
switch(rand() % 4)
{
case 0: cout << "Very good!\n";
break;
case 1: cout << "Nice work!\n";
break;
case 2: cout << "Excellent!\n";
break;
case 3: cout << "Keep up the good work!\n";
break;
}
num3 = rand() % 11;
num4 = rand() % 11;
}
else
{
switch(rand() % 4)
{
case 0: cout << "No. Please try again\n";
break;
case 1: cout << "Sorry. That's not it\n";
break;
case 2: cout << "No. Don't give up\n";
break;
case 3: cout << "Not yet. Keep trying\n";
break;
cout << "How much is " << num1 << " plus " << num2 << "(999 to exit)? ";
cin >> problem;
}
}
}
break;
case 3: problem = 0;
num5 = rand() % 11;
num6 = rand() % 11;
while (problem != 999)
{
cout << "How much is " << num5 << " times " << num6 << " (999 to exit)? ";
cin >> problem;
if ( problem == 999 )
break;
if ( problem == (num5 * num6) )
{
switch(rand() % 4)
{
case 0: cout << "Very good!\n";
break;
case 1: cout << "Nice work!\n";
break;
case 2: cout << "Excellent!\n";
break;
case 3: cout << "Keep up the good work!\n";
break;
}
num5 = rand() % 11;
num6 = rand() % 11;
}
else
{
switch(rand() % 4)
{
case 0: cout << "No. Please try again\n";
break;
case 1: cout << "Sorry. That's not it\n";
break;
case 2: cout << "No. Don't give up\n";
break;
case 3: cout << "Not yet. Keep trying\n";
break;
cout << "How much is " << num1 << " plus " << num2 << "(999 to exit)? ";
cin >> problem;
}
}
}
break;
case 4: cout << "Thank you and have a good day!\n";
break;
default : cout << "Invalid response! please choose (1,2,3,4,or 5)." << endl;
cin >> choice;
}
}while ( choice != 4 );
cin.get();
return 0;
}
This program lets the user decide what type of math they want to do. the rest is a list of random numbers being generated for math problems. does anyone know how to always make num3 greater than or equal to num4 in the subtraction case?
Aucun commentaire:
Enregistrer un commentaire