Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

5. Identify three characteristics of the dialectical approach.

Answered: 1 week ago

Question

6. Explain the strengths of a dialectical approach.

Answered: 1 week ago

Question

4. Explain the strengths and weaknesses of each approach.

Answered: 1 week ago