I recently started taking my first introduction to programming class and am very, very new to it all. My professor's latest programming assignment involves creating a basic math function to calculate several aspects of... well... food orders... I'm having trouble understanding how to make the single function do several calculations involving different identifiers... I'll post the assignment below...
Write a C++ program that reads the number of each meal ordered. Then do the computations and print results as indicated below. The program should compute, for each category, the cost of the meals received in each category, the discount, and the final cost of the meals. It should then compute the total cost of all meals, add a 10% sates tax and print the total due. Be sure to format the output. No loop is necessary.
Make your output is attractive and include appropriate comments in your program. Below is an example of what the inputs and output of the program should look like.
For each meal, Cost Each, Discount, and If order more than should be constants. The calculation of the discount HAS to be done in a function. There should be only 1 function to calculate all three different meal types. The function prototype will look like this:
double calcDiscount (int quantity, double costEach, double discountPerCent, int orderMoreThan);
There is also a small chart included with the meal prices, discount percent to be received, and the amount of meals that must be ordered to receive the discount.... Sorry for the long post, but my professor seems to be a bit slow when it comes to responding to e-mails.
One of the key skills in learning to program is figuring out what the 'user' really wants. This often involves reading what they have written several times (and then asking them suitable questions to clarify things).
In this case the calculation that HAS to be done in the function is the calculation of the discount.
The professor has given you the prototype for calcDiscount - and all that function should do is calculate the discount - nothing more, so it's a fairly simple piece of code.
This is one of the objectives in splitting code into functions, etc. - to make each small block simple. That way it becomes easy to code, test, read, etc.
You can always add more functions to do other parts of the calculation if you wish.
I appreciate the input, Faldrax! I originally misread the assignment. I'm still having trouble understanding what the definition for the Discount function would have to look like in order to calculate different percentages. Would I need to assign identifiers/percentages via cin when the program asks "How many breakfasts were ordered?" for example and use those in the Discount function? I'm so lost :(
For each meal, Cost Each, Discount, and If order more than should be constants.
There is also a small chart included with the meal prices, discount percent to be received, and the amount of meals that must be ordered to receive the discount....
So you have to put the information you have in the chart into a set of constants in your program.
The program will prompt for the number of each type of meals and calculate discounts accordingly.
So if you had
1 2 3 4
double breakfastCost = 10.5;
double breakfastDiscount = 2.25;
int breakfastsForDiscount = 3;
int numberOfBreakfastsOrdered;