CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2011
    Posts
    0

    Need help with calculating the accumulated total

    Hey everyone! Newbie here!
    I've been stuck at a particular programming problem. I have to create an application for selling T-shirts. I have to display the items purchased and calculate the total. Supposed to be easy, right? Arghh!

    So far I've got:
    A ComboBox - this lists the shirts sizes (xsmall. small, medium, large, xlarge, xxlarge). (name: comboShirt)
    Quantity Textbox - This is beside the ComboBox. This is where i enter the quantity of the shirts. (name: txtQuant)
    OK Button - When the user clicks this button, the shirt item and quantity will appear in the listbox. The total amount will appear in the textbox below. (name: btnOK)
    A ListBox - This is where the items selected by the user will appear. (name: lstOrder)
    Amount TextBox - this is where the total amount will appear. (name: txtPay)

    The prices of the shirt are: small, medium, large, xlarge = $16.00 each
    and xsmall, xxlarge = $20.00 each

    Here's a link to the screenshot: tinypic.com/r/w17dw4/7

    Seems pretty basic. But I just cant come up with a code to calculate the total! Can anyone give me any idea as to how to go about that? Do i do a loop? Do an If else statement?
    Also, does the total show up when i click the OK button? Or should i make another button, which the user will click after ordering to calculate the total? I'm totally lost.


    This is the only thing i could come up with. But it doesn't really work. I'm not even sure how to add the $20 prices in this:

    Code:
    private void btnOK_Click(object sender, EventArgs e)
            {
    double total = 0, purchase=16, gtotal, quantity;
                quantity = double.Parse(txtQuant.Text);
                while (quantity != 0)
                {
                    gtotal = quantity * purchase;
                    total += gtotal;
    
                }
                txtPay.Text = purchase.ToString();
                lstOrder.Items.Add(comboShirt.Text + "\t" + txtQuant.Text);
          }
    I'd really appreciate any help with this! I have absolutely no clue how to go about calculating the total. Please point me in the right direction!


    Thanks!

  2. #2
    Join Date
    Oct 2004
    Location
    Rocket City
    Posts
    220

    Re: Need help with calculating the accumulated total

    You have total declared within the btnOK_Click scope so total does not exist anywhere else.
    while (quantity != 0)
    Isn't this an infinite loop?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured