dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Carrying a value

  1. #1
    Join Date
    Sep 2011
    Posts
    0

    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.

  2. #2
    Join Date
    May 2006
    Location
    Dresden, Germany
    Posts
    458

    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:
    Code:
        subtotal + 300.00
    ?

    or this too:
    Code:
            subtotal + 32.00 ;
    ?

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)