Mar 20, 2013 at 12:33am UTC
I am suppose to make a program where the user inputs 3.50 for a twinkie using functions and i am lost. This is what i have.
#include <iostream>
using namespace std;
double get_coins();
int main()
{
const double price = 3.50;
double total_so_far;
double coin_value;
cout << "Please Insert $3.50 to recieve your twinkie" << endl;
do
{
total_so_far =+ get_coins;
}
while(total_so_far < price);
if (total_so_far > price)
{
cout << "Your change is " << total_so_far - price << endl;
}
return 0;
}
double get_coins()
{
int coins;
cout << "Enter 1 for dollars"
<< "Enter 2 for quarters"
<< "Enter 3 for dimes"
<< "Enter 4 for nickels"
<< "Enter 5 for pennies";
cin >> coins;
while(coins == 1 || coins == 2 || coins == 3 coins == 4 || coins == 5);
{
return get_coins_value(coins);
}
}
double get_coins_value(double coin)
{
double coin_value;
switch(choice)
case 1:
coin_value = 1.00;
break;
case 2:
coin_value = .25;
break;
case 3:
coin_value = .10;
break;
case 4:
coin_value = .05;
break;
case 5:
coin_value = .01;
break;
return get_coins_value(coin_value);
}
Last edited on Mar 20, 2013 at 1:59am UTC
Mar 20, 2013 at 12:53am UTC
total so far has to have a starting value
when you call a function you have to use name_of_function(). (this isnt ruby)
when you return something it will leave the current function