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 75 76 77 78 79 80 81 82 83 84
|
Assignment 4b
//
// ********************************************************************************
// Description: This program provides a menu to choose a math problem.
// It then provides two random numbers, asks you to add, subtract, divide, or multiply.
// Once you have the answer, press enter and the program tells you whether you got it right or not.
//
// Created by Christopher Harrod on 3/7/15.
// Status: Complete
//
// ********************************************************************************
#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;
while (choice>4)
{
std::cout << "Please enter a number between 1 and 4.\n";
std::cin >> choice;
}
n1 = rand() % 100 + 1;
n2 = 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 << n1 << "-" << n2 << "=" << "\n\n";
a2 = n1-n2;
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 << n1 << "x" << n2 << "=" << "\n\n";
a3 = n1*n2;
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 << n1 << "/" << n2 << "=" << "\n\n";
a4 = n1/n2;
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;
}
}
|