|
-
September 29th, 2011, 03:21 PM
#1
Carrying a value
Let's say the user makes a choice to buy a TV, so then they are asked if they would like to add insurance and then those two values are added to the subtotal and then tax is added and finally the total. For example
double subtotal = 0.0
double tax = subtotal * .06
double total = tax + subtotal
else if ( choice == 'B' )
{
subtotal + 300.00
cout << "Add insurance ($32.00)? Y/N: ";
cin >> choice;
if ( choice == 'Y' )
{
subtotal + 32.00 ;
}
else if ( choice == 'N' )
{
subtotal + 0.0
}
else
{
cout << " You did not make a correct choice, quitting program " ;
return 0 ;
}
cout << " Your Subtotal is: " << subtotal << endl;
cout << "Tax: " << tax << endl;
cout << " Total: " << total << endl;
return 0 ;
Choice B means they are choosing to buy the TV.
When I run this I just get 0.0 out for all values, so can anyone help me with this? So that if the user orders the tv and insurance the subtotal should be 332.00 and then the rest should work out.
-
September 30th, 2011, 02:14 AM
#2
Re: Carrying a value
First: Please use code tags when posting code to preserve the indentation!
Second: Please post the correct code. Your code cannot be compiled (at least for some missing semicolons). You wrote you got 0.0 for all values when you run this, but you couldn't have run non-compilable code.
What do you think is this line doing:
?
or this too: ?
The second one is better because there is an ending semicolon. But anyway: Both lines do not change the value of subtotal!
You've to assign values with the equal operator ("=") or the compound operators "+=" etc.
With regards
PA
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|