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 62 63 64 65 66 67 68 69 70 71 72 73 74
|
#include <iostream>
#include <cstdlib>
#include <math.h>
int main(int argc, const char * argv[])
{
int n1, n2, n3, n4, n5, n6, n7, n8, a1, a2, a3, a4, a11, a22, a33, a44, choice;
std::cout << "What kind of problem would you like?\n";
std::cout << "Addition, press 1\n";
std::cout << "Subtraction, press 2\n";
std::cout << "Multiplication, press 3\n";
std::cout << "Division, press 4\n";
std::cin >> choice;
n1 = rand() % 100 + 1;
n2 = rand() % 100 + 1;
n3 = rand() % 100 + 1;
n4 = rand() % 100 + 1;
n5 = rand() % 100 + 1;
n6 = rand() % 100 + 1;
n7 = rand() % 100 + 1;
n8 = rand() % 100 + 1;
if(choice == 1)
{std::cout << n1 << "+" << n2 << "=" << "\n\n";
a1 = n1+n2;
std::cout << "What is the answer?";
std::cin >> a11;
if(a1==a11)
std::cout << "Congratulations, you got it right!";
else
std::cout << "Sorry, you got it wrong.";
return 0;
}
else if(choice == 2)
{
std::cout << n3 << "-" << n4 << "=" << "\n\n";
a2 = n3-n4;
std::cout << "What is the answer?";
std::cin >> a22;
if(a2==a22)
std::cout << "Congratulations, you got it right!";
else
std::cout << "Sorry, you got it wrong.";
return 0;
}
else if(choice == 3)
{
std::cout << n5 << "x" << n6 << "=" << "\n\n";
a3 = n5*n6;
std::cout << "What is the answer?";
std::cin >> a33;
if(a3==a33)
std::cout << "Congratulations, you got it right!";
else
std::cout << "Sorry, you got it wrong.";
return 0;
}
if(choice == 4)
{std::cout << n7 << "/" << n8 << "=" << "\n\n";
a4 = n7/n8;
std::cout << "What is the answer?";
std::cin >> a4;
if(a4==a44)
std::cout << "Congratulations, you got it right!";
else
std::cout << "Sorry, you got it wrong.";
return 0;
}
}
|