50Homework – Chapter 6 – Calculator 50 Write a program which allows the user to perform



Homework – Chapter 6 – Calculator:

50. Write a program which allows the user to perform

simple tasks on a calculator. A series of functions allows the user to select an operation to perform and then enter operands.

The first function displays a menu, giving the user the choice of typing in any one of the following:

+, -, *, /, or % A


representing the usual arithmetic operators representing the average of two numbers representing the maximum of two numbers representing the minimum of two numbers representing the square of a number

indicating the user wants to quit the program

The program reads the user’s response into a variable of type char. Using a switch statement or a series of if statements, the program determines what function to call to process the user’s request. For example, if the user enters +, another function asks for two integers. Then it finds the sum of the two integers. If the user enters X, a function asks for two integers and finds the larger of the two. If the user enters S, a function asks for one value and finds the square of that value. If the user enters Q, the program stops.

For each calculation performed, the program (i.e., the function) prints the user’s original input and the resu.

Engineering Technology