Question: C++ ONLY Write a function calculator that takes two floating numbers and one operator and prints out the answer based on arithmetic. Assume that there

C++ ONLY

Write a function calculator that takes two floating numbers and one operator and prints out the answer based on arithmetic. Assume that there are no overflow, underflow and division by zero cases.

  • Your function should be named calculator
  • Your function takes three input parameter: two double numbers and one char operator
  • Your function does not return anything
  • Your function prints answer in the format specified below
  • Your function should set precision point to 2

Note: You must use a switch case for this problem. if/else statements are not allowed.

The format of the output should be = . If an invalid operator is passed to the function, it should print "Invalid operator!"

If the function is called with (3, 7, '+') as the input argument:

3 + 7 = 11

If the function is called with (3, 7, '-') as the input argument:

3 - 7 = -4

If the function is called with (3, 7, '*') as the input argument:

3 * 7 = 21

If the function is called with (3, 7, '/') as the input argument:

3 / 7 = 0.43

If the function is called with (3, 7, '!') as the input argument:

Invalid operator!

Note: You do not need to write the main(), the include, or namespace commands, you only need to write the function definition.

For example:

Test Result
calculator(3, -7, '+');
3 + -7 = -4

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!