These are required and I cannot do it the way you are suggesting .... |
Can I kindly point out that you
can do it the way that it is being suggested.
1 2 3 4
|
//displays the bill
// don't put a return type when calling a function
// at the moment it is a function declaration
void cost(double total, double tax, double tip, double totBill);
|
miah wrote: |
---|
I am not using a return function and I am using variables declared locally. |
assignment wrote: |
---|
2. Global variables may not be used. All variables used in functions must be passed by parameters or declared locally. |
So you don't have to have local variables for every function. The cost function is an example of where the variables are passed as parameters.
48 49 50 51 52 53 54 55 56 57 58 59
|
int main()
{
double item;
double total;
total+=item;
double tax;
tax = total * .065;
double tip;
tip = total * .20;
double totBill;
totBill = total + tax + tip;
double amtTendered;
|
You are doing calculations before you have the values to do them with. That is before you have any code to get the values in the first place. The compiler executes the program in the order that you write the code in main, so you need to put that code which does a calculation after you get all the input.
Also, you have a variable
item
which you are using for 2 things: the cost of an item and the menu option. Create a new variable for the menu option.
You could have a list of variables with the prices of each one:
1 2 3 4
|
const double HamburgerPrice = 6.00;
const double HotdogPrice = 4.50;
// ...
// the rest of them
|
Then use those variable names in your code. If you are clever you can put all the prices into an array, then use the menu option to retrieve the value from the array. Not sure if you have learnt about arrays yet, that might be too advanced :+)
Good Luck !!