Question: Objective: Programming with conditions To evaluate a simple expression, you need to have two numbers and an operator. Assume that the normal operators of addition,

Objective: Programming with conditions To evaluate a simple expression, you need to have two numbers and an operator. Assume that the normal operators of addition, subtraction, multiplication, and division should be recognized. So, If operator is + then number1 + number2 will be evaluated and displayed. If operator is - then number1 - number2 will be evaluated and displayed. If operator is * then number1 * number2 will be evaluated and displayed. If operator is / then number1 / number2 will be evaluated and displayed. Any other operators then Display Unknown operator! message. Note: For division operations, divisor should not be zero.

Question:

(a) Write a C program, that asks the user to enter two numbers (num1 and num2) and an operator (op) and displays the result of expression after evaluation, using else-if commands that allows the user to type in simple expressions of the form number operator number. The program evaluates the expression and displays the results at the terminal, to two decimal places of accuracy. The program, however, is allowed to call the scanf function only once. Remember to have the program check for division by zero.

(b)Write a C program, that asks the user to enter two numbers (num1 and num2) and an operator (op) and displays the result of expression after evaluation, using switch-case commands that allows the user to type in simple expressions of the form number operator number. The program evaluates the expression and displays the results at the terminal, to two decimal places of accuracy. The program, however, is allowed to call the scanf function only once. Remember to have the program check for division by zero.

Hint: Because Raptor has only two simple data types of number and string, the selection of an operator has to be done by comparing the operator input within double quotation marks, e.g., op == +. In C implementation, it is comparisons of two characters in the way as op == +, where op is a char type and the conversion specification for it is %c.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!