Feb 24, 2016 at 1:44am Feb 24, 2016 at 1:44am UTC
Line 68,70: shipping is a local variable. It goes out of scope (is lost) when the function exits.
You really want to modifying shipCost in the caller. To do that though, you have to pass shipCost by reference, not by value as you're doing.
Feb 24, 2016 at 1:48am Feb 24, 2016 at 1:48am UTC
Thanks! got it
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
//*****Function Definitions*****
void displayStandard(double sub, double &shipCost)
{
double shipping = 0.0;
if (sub <= 100)
{
shipping = 12.99;
shipCost = shipping;
}
else
{
shipping = 4.99;
shipCost = shipping;
}
}
void displayPremium(double sub, double &shipCost)
{
double shipping = 0.0;
if (sub <= 49.99)
{
shipping = 4.99;
shipCost = shipping;
}
else
shipping = 0;
}
Last edited on Feb 24, 2016 at 1:49am Feb 24, 2016 at 1:49am UTC
Feb 24, 2016 at 2:01am Feb 24, 2016 at 2:01am UTC
If i wanted the displayPremium to return FREE! rather than 0 for the else, what would need to be done?
1 2 3 4 5 6 7 8 9 10 11 12
void displayPremium(double sub, double &shipCost)
{
double shipping = 0.0;
if (sub <= 49.99)
{
shipping = 4.99;
shipCost = shipping;
}
else
shipCost = 0;
}
Last edited on Feb 24, 2016 at 2:01am Feb 24, 2016 at 2:01am UTC