HOMEWORK 05 - CALCULATOR

Concepts

This assignment exercises your ability to define functions and make function calls.

Calculator Functions

One common application for simple programs is to perform conversions or calculations for the user. In this homework assignment, you will write a program that gives the user a few choices for calculations. Specifically, you will write functions to calculate someone's Body Mass Index (BMI), convert from pounds to kilograms, convert from feet to meters, and one additional calculation of your choice.

For each calculation in your program, you should write (at least) two functions. One function should perform the calculation and return the result, and the other function should accept necessary data from the user, call the calculation function, and then display the result. You should also have a menu function which presents the user with the possible choices for calculations (e.g., user can choose BMI calculation or convert from pounds to kilograms).

Why do we divide your program into functions this way? The primary reason for using functions is so that code is more easily identified and reused. This division ensures that your calculation is universal and can be reused elsewhere.

Get Started

To begin, create an empty project. For the main(), copy/paste the following into your homework project.

int main() {
// DO NOT change this main function

     Menu();

     return 0;

} // end of Main Function

Note that the main function calls a Menu function, which you need to write. Note also that you are not allowed to change the main function. Thus, your Menu function will need to call another function which is associated with the calculation chosen by the user. Fortunately, calling a function from another function works the same way as calling a function from main (as main is also a function).

You should place your function definitions below your main(). To do that, think about what you need to add above your main() to give your functions global scope that can be called from everywhere. (We will discuss function prototypes on Friday.)

The Functions

Your program must have the following functions that perform the described tasks:

Submission

You need to submit your solution of this homework (HW05) with two lab assignments: Lab05A and Lab05B Detailed generic instructions for submitting homework assignments are available. For homework due this Wednesday, follow these specific steps: