Lab 4
In this week's lab you must write a C program to develope a calculator using functions. You will need to know simple input/output, declaring variables, if statements,operations,loops, and how to write and utilize functions(passing the value and returning the value).
The execution of the finished program should look like what is shown below.
Welcome to the calculator.
Your current value is 0
Options are:
1. Add
2. Subtract
3. Multiply
4. Divide
9. Exit
Please enter an operation -> 1
Please enter the number to be added -> 4
Your current value is 4
Options are:
1. Add
2. Subtract
3. Multiply
4. Divide
9. Exit
Please enter an operation -> 4
Please enter the number to be divided -> 3
Your current value is 1
Options are:
1. Add
2. Subtract
3. Multiply
4. Divide
9. Exit
Please enter an operation -> 9
Your final value is 1. Exiting program...
The difference from last week's lab is that we want you to use functions for each of the operations. There should be no mathematical operations in main besides the assignment statement, all of the operations must be performed in separate functions outside main.
Stage 1:
Take the user input and set the current value 0. Declare the functions for all the operations. Use switch case to define the menu options.
Stage 2:
It should ask once what operation to perform on the initial value of 0, and then based on that input perform that operation, print out the result, then "loop back" and ask the user what operation they would like to perform next. As a starting point use the sample file provided.
Stage 3 (Extra Credit):
Add a menu option to display the currently stored number in binary. Assume the number is 0..255, which should give output of 8 bits.
Notes:
Keep in mind that this is a team effort so you should agree with your partner on what you are going to do before you start typing. The partner who is typing is the "driver" and the partner watching is the "navigator." Be sure to switch roles every 10 to 15 minutes, to foster a deep understanding of the code for both partners. The navigator should be watching for syntax errors and verifying the correctness of the code you're writing.
It will speed things up for you if you keep a window open for editing and have a separate window open for compiling and running your program. Remember that windows are resizeable!
Submission:
You should work with a partner for a grade. Only one submission per group is necessary, but be sure to include your name if you work alone, or both people's names if you worked with a partner.
You should submit the lab at the end of the lab session, by 50 minutes after the hour. If you do not finish the lab, you may submit the lab by noon on Friday for a 1 point penalty. (1:50 for 1 pm lab, 2:50 for 2 pm lab, 3:50 for 3 pm lab and 4:50 for the 4 pm lab) .