Question: Code is in c. Need main.c, math.h, math.c. A small calculator We've seen enough now that you can start writing some simple but useful code.

Code is in c. Need main.c, math.h, math.c.  Code is in c. Need main.c, math.h, math.c. A small calculator
We've seen enough now that you can start writing some simple but

A small calculator We've seen enough now that you can start writing some simple but useful code. For this assignment, you'll write a six-function calculator that returns the result of addition, subtraction, multiplication, division, and raising a number to a power (in two different ways). You'll turn this in using GitLab, and we'll provide instructions on how to set that up separately. The problem: Overview There are of course a lot of approaches to writing a calculator, but for this assignment there's just one. Here's what you'll need to do: Use a do-while loop to prompt the user to enter a mathematical expression. For this calculator, expressions are in a fixed format (use %f%c%f): NumberOperatorNumber For example, if you'd like to add 5 and 12 together, the expression would be 5+12 with no spaces between the numbers and the operator. The operators are: +, - /,^ (for power) and $ (for recursive power). By 'power' I mean something like 25. Use scanf to read in each of the three values (two numbers and an operator) from the fixed- format expression. If the user enters an incorrectly formatted expression, horrible things will happen and you'll likely need to halt the program manually. (Why? The scanf() function has some pretty serious problems around input that doesn't exactly match its format specifier. There are better solutions in C, but we still need to talk about a few language features before we can use them.] Once you have all three values, use a switch statement to execute one of six functions (one for each operator). The functions should be named: add, subtract, multiply, divide, power, and recursivePower Finally print the result in the format: Result: Your printed result should display 2 digits of precision, no more, no less. NOTE: Your 'recursivePower' function must use recursion, and your non-recursive power function must use a loop to calculate its value -- you may not use built-in math functions. Organization Your math functions should be in a separate pair of files, math.c and math.h. You'll end up with three files: main.c, math.h, and math.c (plus a file for your results, see below). Testing Test your calculator with the following entries: 123.456+567.890 123.456-567.890 123.456'567.890 123.456/567.890 448 4$8 Capture the output of each of these operations and paste them into a text file in your project named psOresults.txt Submitting your work In the next few days we'll talk about using glt along with GitLab to store and submit your assignments for the rest of the course. Hang tight until we've had that discussion

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!