1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Need help with calculating the accumulated total

Discussion in 'C#' started by xxsonika, Mar 7, 2011.

  1. xxsonika

    xxsonika New Member

    Hey everyone! Newbie here! :D
    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 best idea i could come up with. But it doesn't really work. I'm not even sure how to add the $20 prices in this:

    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!


Share This Page