Homework 4 - UMBC-CMSC104/General GitHub Wiki
For this program, we're going to be using functions. Functions are explained in the reading and will be explained in Thursday's class (9/27).
Name the code for this assignment calculator.c.
You are to write a program that allows the user to add, subtract, multiply, divide, or modulus two numbers:
Welcome to homework 4!
Please select an option:
1) Add two numbers
2) Subtract two numbers
3) Multiply two numbers
4) Divide two numbers
5) Modulus two numbers
Each menu option must be implemented in a function. An example skeleton program that only calls add:
#include <stdio.h>
/* Function definition */
void add()
{
....
}
int main()
{
add(); /* Function call */
return 0;
}
Each function must declare, read in its own variables (scanf), perform the correct operation (addition, subtraction, multiplication, division, modulus), and print out the result. Each function will be declared as demonstrated above. Additionally, each function is called in main the same way.
You are required to use a switch statement for the menu.
To submit it, type
submit cs104_wilson hw04 calculator.c
- Refer to classwork 5 and your book for function information.
- Refer to the reference implementations code.
- Don't forget -- the new clamp down procedures are in effect! Proper indentation, code commenting, file headers, and proper variable names are required!