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

Design an algorithm that will read two numbers and an integer code from the scre

ID: 3754101 • Letter: D

Question

Design an algorithm that will read two numbers and an integer code from the screen. The value of the integer code should be 1, 2, 3 or 4. If the value of the code is 1, compute the sum of the two numbers. If the code is 2, compute the difference (first minus second). If the code is 3, compute the product of the two numbers. If the code is 4, and the second number is not zero, compute the quotient (first divided by second). If the code is not equal to 1, 2, 3 or 4, display an error message. The program is then to display the two numbers, the integer code and the computed result to the screen.

Explanation / Answer

Step 1- Ask the user for the input of two numbers and integer code.

Step 2 - accept the input from user and store it in variable and input code in another variable (say code).

Step 3- put code in the switch as switch(code)

Step 4- put the case accordingly like case 1 for addition, case 2 for subtraction, case 3 for multiplication and case 4 for division and a default case that print an error message if the code is not equal to 1,2,3 or 4. store this output in some variable.

Step 5- print the numbers, integer code and also the result from step 4

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