Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am trying to write a C++ program in which two 2-digit random numbers are gener

ID: 3620172 • Letter: I

Question

I am trying to write a C++ program in which two 2-digit random numbers are generated then used to ask a young student to choose a math problem; addition, subtraction, or multiplication. The program is as follows:

#include
#include // for time function
#include // for the srand and rand functions
using namespace std;

int main ()
{

{
// 1. Generate two random single-digit integers
srand(time(0));
int number1 = rand() % 100;
int number2 = rand() % 100;

// 2. If number1 < number2, swap number1 with number2
if (number1 < number2)
{
int temp = number1;
number1 = number2;
number2 = temp;
}

// 3. Define OPERATION, ADDITION, SUBTRACTION, MULTIPLICATION
int OPERATION, ADDITION, SUBTRACTION, MULTIPLICATION;
OPERATION = ADDITION, SUBTRACTION, MULTIPLICATION;
ADDITION = number1 + number2;
SUBTRACTION = (number1 - number2);
MULTIPLICATION = (number1 * number2);

// 4. Program queries student
cout << "which would you like to do, ADDITION, SUBTRACTION, or M
ULTIPLICATION? ";
cin >> OPERATION;

// 5. Program processes appropriate operation

switch (OPERATION)
{
case 1:
cout << "What is " << number1 << " + " << number2;
break;
case 2:
cout << "What is " << number1 << " - " << number2;
break;
case 3:
cout << "What is " << number1 << " * " << number2;
break;
default:
cout << "ERROR";
break;
}
"Math.cpp" 55 lines, 1200 characters
-bash-3.00$ g++ Math.cpp
-bash-3.00$ ./a.out Math.cpp
which would you like to do, ADDITION, SUBTRACTION, or MULTIPLICATION?
SUBTRACTION
-bash-3.00$ ./a.out Math.cpp
which would you like to do, ADDITION, SUBTRACTION, or MULTIPLICATION?
MULTIPLICATION
What is 56 * 15-bash-3.00$ ./a.out Math.cpp
which would you like to do, ADDITION, SUBTRACTION, or MULTIPLICATION?
ADDITION
What is 86 * 50-bash-3.00$ ./a.out Math.cpp
which would you like to do, ADDITION, SUBTRACTION, or MULTIPLICATION?
NOTHING
What is 37 * 3-bash-3.00$ vi Math.cpp
"Math.cpp" 55 lines, 1200 characters


When I compile the program then test it every operation, addition, subtraction & multiplication gives me the response for multiplication (case 3) how do I fix this so that each case gives me the appropriate response?

I have included the response given each time I compiled and tested the program.

Explanation / Answer

#include<iostream>
#include<ctime> // for time function
#include<cstdlib> // for the srand and rand functions
using namespace std;

int main ()
{

// 1. Generate two random single-digit integers

srand(time(0));
int number1 = 1+rand() % 100;
int number2 = 1+rand() % 100;

// 2. If number1 < number2, swap number1 with number2
if (number1 < number2)
{
int temp = number1;
number1 = number2;
number2 = temp;
}

// 3. Define OPERATION, ADDITION, SUBTRACTION, MULTIPLICATION
char OPERATION;

// 5. Program processes appropriate operation

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote