Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ***********************************************************************
- // File: <mathtutor2.cpp>
- //
- // <module name> - <description>
- //
- // Author: <Julia Coleman>
- // Created: <01/24/2011>
- // Updated: N/A
- //
- // Assignment: <lab 2>
- // Compiler: < >
- //
- // *********************************************************************
- // Inputs: <seed, answer, remainder>
- //
- // Outputs: <num1, num2>
- //
- // Constraints: <>
- //
- // *********************************************************************
- // Design
- // <Int main
- // Int operation, num1, num2, answer, remainder
- // Unsigned seed
- //
- /** Get user to input integer
- If number is a valid number say thanks
- If number is not a valid number, end program
- Ask user which operation they would like to perform
- (Addition, Subtraction, Multiplication, and Division)
- If addition, add random numbers
- If subtraction, subtract random numbers
- If multiplication, multiply random numbers
- If division, divide random number
- For all, ask for input and then tell them if it's the right or
- wrong answer. If it is a wrong answer tell them the right one.
- */
- #include <iostream>
- #include <cstdlib>
- #include <iomanip>
- using namespace std;
- int main()
- {
- int operation, num1, num2, answer, remainder,continuity;
- unsigned seed;
- srand (seed);
- cout <<"Please enter a number that is greater than 0: \n";
- cin >> seed;
- if (seed > 0)
- cout << "Thank you\n\n";
- else
- {
- cout << "That is not a valid input\a";
- return 0;
- }
- num1 = 0 + rand() % 9999;
- num2 = 0 + rand() % 9999;
- //ask user which math operation they would like to preform
- cout <<"Math Tutorial Program\n";
- cout <<"1. Addition\n";
- cout <<"2. Subtraction\n";
- cout <<"3. Multiplicatio\n";
- cout <<"4. Division\n";
- cout <<"Press Q to quit\n";
- cout <<"Which math operation would you like to practice?\n";
- cin >> operation ;
- if (operation > 0)
- cout << "\n";
- else
- {
- cout << "That is not a valid input";
- return 0;
- }
- switch (operation)
- {
- case 1: cout << num1 <<endl;
- cout << "+" <<num2 << endl;
- cout << "_____\n";
- cin >> answer;
- if (answer > 0)
- cout << "\n";
- else
- {
- cout << "That is not a valid input";
- return 0;
- }
- if (answer == num1 + num2)
- cout<<"Good Job! That is correct!\n";
- else
- cout<<"Sorry. The answer is: "<< num1 + num2<<endl;
- break;
- case 2: cout << num1 <<endl;
- cout << "-" <<num2 << endl;
- cout << "_____\n";
- cin >> answer;
- if (answer > 0 || answer < 0)
- cout << "\n";
- else
- {
- cout << "That is not a valid input";
- return 0;
- }
- if (answer == num1 - num2)
- cout<<"Good Job! That is correct!\n";
- else
- cout<<"Sorry. The answer is: "<< num1 - num2<<endl;
- break;
- case 3: cout << num1 <<endl;
- cout << "x" <<num2 << endl;
- cout << "_____\n";
- cin >> answer;
- if (answer > 0 || answer < 0)
- cout << "\n";
- else
- {
- cout << "That is not a valid input";
- return 0;
- }
- if (answer == num1*num2)
- cout <<"Good Job! That is correct!\n";
- else
- cout <<"Sorry. The answer is: "<< num1*num2<<endl;
- break;
- case 4:
- cout << "The program will ask you for the whole number and then the remainder.\n";
- if(num1<num2)
- num1=num2+23;
- cout << num1 << "/" <<num2 << "=" <<endl;
- cin >> answer;
- if (answer > 0 || answer < 0)
- cout << "\n";
- else
- {
- cout << "That is not a valid input";
- return 0;
- }
- cout << "What is the remainder of " << num1 <<"/"<<num2 <<"? ";
- cin >> remainder;
- if (answer > 0 || answer < 0)
- cout << "\n";
- else
- {
- cout << "That is not a valid input";
- return 0;
- }
- if (answer == num1/num2 && remainder == num1%num2)
- cout << "Good Job! That is correct!\n";
- else
- cout << "Sorry the answer is " <<num1/num2 <<" r "<<num1%num2 <<endl;
- break;
- case 'Q': cout <<"Thanks!";
- return 0;
- default: cout << "1,2,3,4 and Q are the only valid choices.";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement