Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This program displays a list of operations and allows an elementary student pick from te list. For the selected operation, the program generates Random Numbers.
- #include <iostream>
- using namespace std;
- #include <cstdlib>
- #include <ctime>
- int main()
- {
- //Instruction Display, Declaration and Input.
- cout << "Find Below instructions regarding operations to be performed. Please Choose from this List. " << endl;
- cout << "Choose 1 for Addition." << endl;
- cout << "Choose 2 for Subtraction." << endl;
- cout << "Choose 3 for Multiplication." << endl;
- cout << "Choose 4 for Division" << endl;
- int choice;
- enum Selected_Choice {Subtraction=1, Division} selected_choice;
- cout << "Enter your choice : ";
- cin >> choice;
- //Variable Declaration
- int number1, number2, number3, subtraction, answer;
- double division;
- // Generating Two Random numbers
- srand(time(0));
- number1 = 1+ rand() % 10;
- number2 = 1+ rand() % 10;
- // Code
- switch (choice)
- {
- case Subtraction:
- // to avoid negative
- if (number1 < number2)
- {
- int temp = number1;
- number1 = number2;
- number2 = temp;
- }// Swaping
- cout << number1 << " - " << number2 << " = " " ? " << endl;
- cout << " Enter your Answer : ";
- cin >> answer;
- subtraction = number1 - number2;
- if (answer == subtraction)
- cout << " Correct Answer; Good Job ! " << endl;
- else
- cout << " Wrong Answer. The correct answer is " << subtraction << endl;
- break;
- case Division :
- cout << number1 << " divided by " << number2 << " is ? " << endl;
- cout << "Enter your Answer : ";
- cin >> answer;
- division = number1 / ststic_cast <double> (number2); //missing cast
- if (answer == division)
- cout << " Correct Answer; Good Job ! " << endl;
- else
- cout << " Wrong Answer. The correct answer is " << division << endl;
- break;
- default :
- cout << " You have chosen a wrong Command!! " << endl;
- } // Switch Cases
- cout << " Thank you for taking this test." << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement