Question

In: Computer Science

hello! So I have this CIS assignment lab but when I try to make the code...

hello! So I have this CIS assignment lab but when I try to make the code I don't really know where to start from. My professor is very hard and he likes to see the outcomes as they are shown in the problem. Please help me!

Write a program that can be used as a math helper for an elementary student. The program should display two random integer numbers that are to be added, such as:
    247
+ 129
-------

The program should wait for the students to enter the answer. If the answer is correct, a message of congratulations should be printed. If the answer is incorrect, a message should be printed showing the correct answer.

The program displays a menu allowing the user to select an addition, subtraction, multiplication, or division problem. The final selection on the menu should let the user quit the program. After the user has finished the math problem, the program should display the menu again. This process is repeated until the user chooses to quit the program.
Input Validation: If the user select an item not on the menu, display an error message and display the menu again.

Requirements:

Addition
Generate two random numbers in the range 0 - 9.

Subtraction

Generate two random numbers in the range 0 - 9.
num1 = rand() % 10;
num2 = rand() % 10;
Make sure num2 <= num1...
while (num2 > num1)
num2 = rand() % 10;

Multiplication

Generate two random numbers. The first in the range 0 - 10, the second in the range 0 - 9.

Division

Generate a single digit divisor
num2 = rand() % 9;
Generate a num1 that is a multiple of num2 so the division has no remainder. The num1 is never zero.
num1 = num2 * (rand() % 10 + 1);

All constant values must be declare as a constant variable. Use the constant variable in the calculation.
Validating the selection (1 to 5). If the selection is not in the range between 1 and 5, the program keeps asking the input until the correct selection is entered.
Comments in your program to explain the code logic and calculation.


Output sample:

Menu
1. Addition problem
2. Subtraction problem
3. Multiplication problem
4. Division problem
5. Quit this program

Enter your choice (1-5): 1
   1
+ 2
   ---
   4

Sorry, the correct answer is 3.
Menu
1. Addition problem
2. Subtraction problem
3. Multiplication problem
4. Division problem
5. Quit this program
Enter your choice (1-5): 7
The valid choices are 1, 2, 3, 4, and 5. Please choose: 2
    8
+ 6
    ---
    2
Congratulations! That's right.
Menu
1. Addition problem
2. Subtraction problem
3. Multiplication problem
4. Division problem
5. Quit this program
Enter your choice (1-5): 3
     9
*   4
    ---
   36

Congratulations! That's right.
Menu
1. Addition problem
2. Subtraction problem
3. Multiplication problem
4. Division problem
5. Quit this program
Enter your choice (1-5): 4
8 / 2 = 4
Congratulations! That's right.
Menu
1. Addition problem
2. Subtraction problem
3. Multiplication problem
4. Division problem
5. Quit this program
Enter your choice (1-5): 4
6 / 2 = 3
Congratulations! That's right.
Menu
1. Addition problem
2. Subtraction problem
3. Multiplication problem
4. Division problem
5. Quit this program
Enter your choice (1-5): 5

"Thank you for using math helper!"

Solutions

Expert Solution

To solve this problem I'm using Python Language ---

ALGORITHM ---

At the very beginning we need to declare two variables which is ranged between 0 to 9 , the only ten digits.

Let the numbers are num1 and num2.Then we have to make four functions for each specific works (Add,Sub,Mul,Div).We just add the two integers formed randomly like as ; num1+num2.

The sub is same as the add just we just need to add some conditions like if the first digit is smaller than the second one then we get a negative sign . So to avoid this sign we just need one condition the second number have to be smaller than the first one like as ; num2<=num1.

The mul is nothing just we have to multiply the both numbers and get the result.

The div is quite amazing.Here we need to see upon the divisor because if the divisor is one digit then we have to give a condition that is; num2 = rand() % 9 and generate a num1 that is a multiple of num2 so the division has no remainder. The num1 is never zero.num1 = num2 * (rand() % 10 + 1);All constant values must be declare as a constant variable. Use the constant variable in the calculation.

CODE ---

[ In the programme I use the first and the second number as a & b in place of num1 and num2 ]

import random as r
while(1):
   print('\n')
   print("Menu\n")
   print("1. Addition Problem")
   print("2. Subtraction Problem")
   print("3. Multiplication Problem")
   print("4. Division Problem")
   print("5. Quit This Problem")
   print("\n Enter Your Choice (1-5)::",end='')
   n=0
   while(n not in [1,2,3,4,5]):
       n=int(input())
       if(n not in [1,2,3,4,5]):
           print("\nThe valid choices are 1, 2, 3, 4 and 5. Please Choose: ",end='')

   print('\n')
      
   if(n==1):
       a=r.randint(1,9)
       b=r.randint(1,9)
       c=a+b
       print('\t',a)
       print(' ','+',b)
       print(' ----')
       d=int(input(' '))
       if(d==c):
           print("\n Congratulations! That's Right.")
       else:
           print("\nSorry, The Correct Answer is",c)
   elif(n==2):
       a=r.randint(1,9)
       b=r.randint(1,9)
       while(a<b):
           a=r.randint(1,9)
           b=r.randint(1,9)
       c=a-b
       print('\t',a)
       print(' ','-',b)
       print(' ----')
       d=int(input(' '))
       if(d==c):
           print("\n Congratulations! That's Right.")
       else:
           print("\n Sorry, The Correct Answer is",c)
   elif(n==3):
       a=r.randint(1,9)
       b=r.randint(1,9)
       c=a*b
       print(a,"*",b,'=',end='')
       d=int(input(' '))
       if(d==c):
           print("\n Congratulations! That's Right.")
       else:
           print("\n Sorry, The Correct Answer is",c)
   elif(n==4):
       b=r.randint(1,9)
       c=r.randint(1,9)
       a=b*c
       print(a,"/",b,'=',end='')
       d=int(input(' '))
       if(d==c):
           print("\n Congratulations! That's Right.")
       else:
           print("\nSorry, The Correct Answer is",c)
   elif(n==5):
       exit()

[If My code will help you then give my effort a thumbs up ]


Related Solutions

How would I make it so that when I run my code it does not ask...
How would I make it so that when I run my code it does not ask for input (not having to enter after the statement and enter 0 for example) after ROXY (Forever ROXY Enterprises) appears? Like it would tell me the second statement right away along with the Roxy phrase. This is in C++. My code: #include / #include using std::endl; int main() {    void readAndConvert();    unsigned int stockSymbol;    unsigned int confNum;    std::cout << "ROXY...
So I have a lab practical coming up; how do I know when to take an...
So I have a lab practical coming up; how do I know when to take an IR spec versus making a TLC chamber? Follow up question: Can someone walk me through the interpretation of a TLC chamber?
hello everyone, i have this assignment to do and i dunno how to structure it as...
hello everyone, i have this assignment to do and i dunno how to structure it as i didnt have enough informations about the layout and the structure. please provide me with the structure starting from the introduction, excutive summary,...,.....,......,.......,conclusion and references. i need to fill up the paragraphs but i dunno what to layout. Assume your group comprises the Sydney City Council. In an effort to reduce inner city congestion, there is already a project to establish light rail. But...
Hello I have this error in the code, I do not know how to fix it....
Hello I have this error in the code, I do not know how to fix it. It is written in C++ using a Eclipse IDE Error: libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: basic_string bus.h =========== #pragma once #include using namespace std; class Bus { private:    string BusId; // bus ID    string Manufacturer; // manufacturer of the bus    int BusCapacity; // bus capacity    int Mileage; // mileage of bus    char Status; // current status...
Hello, I have an online discussion assignment due. and I don't have an idea about the...
Hello, I have an online discussion assignment due. and I don't have an idea about the questions. 1. Analyze economic choices and trade-offs 2. Analyze economic models. Would you help me with that? Typed answer is preferred. Thank you very much in advance! -------------------------------------------------------------------------- D1: Should Abortion Be Leagal Discussion Expectations Respond to at least two other peer postings.  Be substantive and follow up on your comments and questions. Do you agree or disagree and why.  Do you have questions based on...
So I have written a code for it but i just have a problem with the...
So I have written a code for it but i just have a problem with the output. For the month with the highest temperature and lowest temperature, my code starts at 0 instead of 1. For example if I input that month 1 had a high of 20 and low of -10, and every other month had much warmer weather than that, it should say "The month with the lowest temperature is 1" but instead it says "The month with...
Hello, i have this assignment i have tried solving it but been hitting road blocks how...
Hello, i have this assignment i have tried solving it but been hitting road blocks how do i solve this also, i have the texas BA II PLUS Calculator can you tell me how to solve for this using the fomular approach Thank you Questions Based on the following cash flows, which of the following mutually exclusive project would you choose? You require a 15% return on your investment. Year 0 (Initial Investment) 1 2 3 4 Project #1 ($300,000)...
So, I have this Matlab program that I have made for a lab, and despite having...
So, I have this Matlab program that I have made for a lab, and despite having different frequencies, when I go to plot them, the graphs look exactly the same. Can someone tell me why that is? I also need to know how to determine the digital frequencies(rad/sec) and how many samples per period of both of the waves? Thank you Code: N = 100; % Total number of time domain samples in simulation. A1 = 1; % Amplitude of...
Hello I have these questions, I would like not so long answers but something that gives...
Hello I have these questions, I would like not so long answers but something that gives me a good idea about the topic. What is a perfectly competitive market? Why are many agricultural products in a perfectly competitive market? What is a price taker? What are barriers to entry in a market? What is a standardized product? Give an example What is a company’s market share? What is free entry and exit? How do you calculate a company’s total revenues?...
Hello I have these questions. I need good answers in order to undertand not so long...
Hello I have these questions. I need good answers in order to undertand not so long nor so short please Why are consumers willing to pay more for small portions? What is the substitution effect of a higher price on a consumer? What is the income effect of a higher price on a consumer?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT