Question: Programming Language used: C Part 2: Basic Calculator In the file calc.c, the main method is already written for you. The main method reads from

Programming Language used: C

Part 2: Basic Calculator

In the file calc.c, the main method is already written for you. The main method reads from standard input an expression of the following form:

There is also a function called doMath which takes two integer arguments and a character argument and returns an integer value. The first two arguments are the operands collected from input in the same order as they appear. The last character argument is the ASCII representation of the math operator from input.

Your job is to finish the doMath function so that it supports the following operations:

Addition (+)

Subtraction (-)

Multiplication (*)

Division (/)

Remainder (%)

XOR (^)

Logical AND (&)

Logical OR (|)

The function should return the mathematical result of the operation on the two operands.

Use a switch statement. This function can and should be done without the use of if statements. The default case is that the doMath function print an error message and then should call the function exit(EXIT_FAILURE).

The exit function allows the program to terminate immediately from any point in the code and the argument to it is a status code. Well discuss this function further as we discuss larger projects. For now, just use it as is.

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!