void function with 4 parameters that must display
Mar 31, 2016 at 2:06am UTC
Thats what i was thinking const ints or doubles to pass the values. Not real sure how I am gonna get the variables before I call them into the function though. Will definently watch a couple videos on arrays though I think I can get that. Its just frustrating when you have no wxample of exactly what you want to do and all you can do is guess. I'll see if I can't put this together differently. Thank you
Mar 31, 2016 at 2:22am UTC
Not real sure how I am gonna get the variables before I call them into the function though.
Some pseudo code:
1 2 3 4
// Show the Menu
// get some input
// call functions to do some calculations
// show the results
Mar 31, 2016 at 3:35am UTC
More orderly and when I just use cout it works correctly or when I have no parameters to the function works fine so still same predicament I need an example of how a parameter function is used to to display " " and variables ???
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
#include <iostream>
#include <iomanip>
using namespace std;
void display()
{
cout << "*** BASEBALL GAME SNACK MENU ***" << endl;
cout << "----------------------------------------------" << endl;
cout << "1 Hamburger $6.00" << endl;
cout << "2 Hotdog $4.50" << endl;
cout << "3 Peanuts $3.75" << endl;
cout << "4 Popcorn $5.50" << endl;
cout << "5 Soda $2.80" << endl;
cout << "6 Chips $1.00" << endl;
cout << "7 Water $2.00" << endl;
cout << "8 end order " << endl << endl;
}
void cost(double total, double tax, double tip, double totBill)
{
cout << "The subtotal is: " << setprecision(2) << fixed << total << endl;
cout << "Tip comes to: " << setprecision(2) << fixed << tip << endl;
cout << "Tax on your purchase is: " << setprecision(2) << fixed << tax << endl;
cout << "Your total bill is: " << setprecision(2) << fixed << totBill << endl;
}
int main()
{
const double hamburgerPrice = 6.00;
const double hotdogPrice = 4.50;
const double peanutsPrice = 3.75;
const double popcornPrice = 5.50;
const double sodaPrice = 2.80;
const double chipsPrice = 1.00;
const double waterPrice = 2.00;
double item;
double total = 0.0;
//displays menu
display();
while (item !=8)
{
//displays enter item until 8 is selected
cout << "Enter Menu Items #:" << endl;
cout << "----------------" << endl;
cin >> item;
cout << endl;
if (item ==1)
{
item = hamburgerPrice;
}
else if (item ==2)
{
item = hotdogPrice;
}
else if (item ==3)
{
item = peanutsPrice;
}
else if (item ==4)
{
item = popcornPrice;
}
else if ( item ==5)
{
item = sodaPrice;
}
else if (item == 6)
{
item = chipsPrice;
}
else if (item == 7)
{
item = waterPrice;
}
else if ( item == 8)
{
item = 0;
break ;
}
total += item;
}
double tip;
tip = total * .20;
double tax;
tax = total * .065;
double totBill;
totBill = total + tax + tip;
void cost(double , double , double , double );
}
Mar 31, 2016 at 3:59am UTC
Ok, we are getting there :+)
TheIdeasMan wrote: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.
So do that :+) and use it in the if statements.
1 2 3
if (MenuOption == 1)
{
total += hamburgerPrice;
Then you can remove line 92, and not have an
item
variable at all !
I gave you some wrong information earlier, call a function with the values you want to send to it, without any types:
cost( total, tax, tip, totBill);
The compiler doesn't need the types there, because you have already provided a function definition.
This part:
1 2 3 4 5 6
double tip;
tip = total * .20;
double tax;
tax = total * .065;
double totBill;
totBill = total + tax + tip;
can be written like this, we can delay the declaration of a variable until we have a sensible value to assign to it:
1 2 3 4 5
double tip = total * 0.20;
double tax = total * 0.065;
double totBill = total + tax + tip;
Hope that helps :+)
Mar 31, 2016 at 4:03am UTC
great it works perfecr like that?? I would have spent another day banging my head now just write the void Tcash function and I will have it made thank you again
Topic archived. No new replies allowed.