Answered Radio buttons and check boxes with math

jag250

Active member
Joined
Sep 16, 2020
Messages
28
Programming Experience
1-3
http://miscapstone.uncw.edu/316f20matthewsk/MIS316/MP1Bmatthewsk.aspx
This is the project I have to build
I have created the online of the page and 3/4 panels are functioning and my textboxes are good to go.
I need help trying to get the math portion done and the radio and checkbox buttons. if you check the sample site you can see what parts I am missing. I am going to continue doing what I can, but help or a general outline of what I am missing would be greatly appreciated.
Screenshot 2020-09-16 14.01.55.png

C#:
protected void Button1_Click(object sender, EventArgs e)
{
    //input variable
    string name = "";
    int numbagels = 0;

    //variables to labels
    name = txtName.Text;
    numbagels = Convert.ToInt32(txtNumofBagels.Text);

    lblOrderFor.Text = name;
    lblNumberofBagels.Text = numbagels.ToString();

    if (rbCarryOut.Checked == true)
    {
        lblOrderType.Text = "Carry Out";
        lblChargeTax.Text = "No";
    }
    else
    {
        lblOrderType.Text = "Dine In";
        lblChargeTax.Text = "Yes";
    }
    pnlCustomer.Visible = false;
    pnlDineorCarry.Visible = true;
}


protected void btnFinishOrder_Click(object sender, EventArgs e)
{
    pnlDineorCarry.Visible = false;
    pnlFinishOrder.Visible = true;

    //input variable
    string name = "";
    int numbagels = 0;

    name = txtName.Text;
    numbagels = Convert.ToInt32(txtNumofBagels.Text);
 
Last edited by a moderator:
You write your own code on here.

We help you when you experience problems with that code.

rbWheat.Text = "$1.00";
rbEverything.Text = "$1.50";

cbToasted.Text = "$0.50";
cbCreamCheese.Text = "$1.00";

this is what I have so far. I gave the radio buttons and check boxes values
I just cant figure out how to start the formula
 
You already have a thread about this open. Merging threads...
 
You already have a thread about this open. Merging threads...
 
I also moved this thread to Web Forms since it looks like the OP is trying to do this in Web Forms, and not just as a general C# discussion.
 
I need to create a C# formula that adds a $2.00 base fee plus any add ons (listed below). one with a tax of 7% (dine in) and one without (carry out)
Slow down. How how you create this formula with pen and paper? Do you recall your high school algebra (or grade school algebra for some Gen X and later)? How would you write the algebraic equation for this problem? Algebraic equations usually translate into C# assignment statements very easily.

Here's a simple example: Newton's second law is F = ma. In words, it's force is equal to mass times acceleration. So the C# code for that equation is:
C#:
force = mass * acceleration;
 
if (rbPlain.Checked == rbDineIn.Checked)
{
decimal Plain = Convert.ToDecimal(rbPlain.Checked);
Plain = 2.00m;
decimal decTax = 0.07m;


SubTotal = TypeofBagel


lblSubTotal = (rbPlain * lblNumberof);

lblTax = (lblSubTotal * 0.07m);
Total = decTax + lblSubtotal.text;



}
else if (rbWheat.Checked == rbDineIn.Checked)
{


decimal Wheat = Convert.ToDecimal(rbPlain.Checked);
Wheat = 1.00m;
decimal decTax = 0.07m;
lblSubTotal = (rbWheat * lblNumberof);

lblTax = (lblSubTotal * 0.07m);
Total = decTax + SubTotal;

lblSubtotal.Text = decSubtotal.ToString("c")
lblTax.Text = decTax.ToString("c")
lblTotal.Text = decTotal.ToString("c"
}

else
{
decimal Everything = Convert.ToDecimal(rbPlain.Checked);
Everything = 1.00m;
decimal decTax = 0.07m;
lblSubTotal = (rbEverything * lblNumberof);

lblTax = (lblSubTotal * 0.07m);
Total = decTax + SubTotal;

lblSubtotal.Text = decSubtotal.ToString("c")
lblTax.Text = decTax.ToString("c")
lblTotal.Text = decTotal.ToString("c"

}



if (rbCarryOut.Checked == true)
{
lbldineorcarry.Text = "Carry Out";
//lblTax.Text = lblSubTotal.Text * Tax;
//lblTotal.Text = lblSubTotal.Text + lblTax.Text;
//lblSubTotal.Text = "$" + SubTotal.ToString;
}

else
{
lbldineorcarry.Text = "Dine In";
// lblTax.Text
// lblTotal.Text = lblSubTotal.Text + lblTax.Text;
}

//input variable
string name = "";
int numbagels = 0;

name = txtName.Text;
numbagels = Convert.ToInt32(txtNumofBagels.Text);

//set labels
lblname.Text = "order for " + name;
lblNumberof.Text = numbagels.ToString();



rbWheat.Text = "$1.00";
rbEverything.Text = "$1.50";

cbToasted.Text = "$0.50";
cbCreamCheese.Text = "$1.00";





if (rbPlain.Checked == true)
{
lblTypeof.Text = "Plain Bagels";
}
else if (rbWheat.Checked == true)
{
lblTypeof.Text = "Wheat Bagels";
}
else if (rbEverything.Checked == true)
{
lblTypeof.Text = "Everything Bagel";

}

This is what I have come up with. However, a lot of it is in red. I could use some help on how to make it flow better.
Thx
 
Last edited:
I just started learning C# 3 weeks ago

According to one of the other teachers teaching MIS 316:
Prerequisite: MIS 216 or CSC 112 or CSC 131 or another programming language course approved by the department chair.

In my mind, that means you shouldn't be struggling with how to put together the formula for computing the total. It's quite possible that you may be running into issues understanding how the WebForms page life cycle works (even experienced developers have to go look at the chart every now and then), but based on the code above, it looks like you are truly struggling with the forumla. If you don't mind me asking, what was the previous programming language course that you took?
 
According to one of the other teachers teaching MIS 316:


In my mind, that means you shouldn't be struggling with how to put together the formula for computing the total. It's quite possible that you may be running into issues understanding how the WebForms page life cycle works (even experienced developers have to go look at the chart every now and then), but based on the code above, it looks like you are truly struggling with the forumla. If you don't mind me asking, what was the previous programming language course that you took?
i only have taken python and that was over a year ago
 
And how would you write that formula in Python?
 
To quote Bob Carter: "Lack of planning on your part does not constitute an emergency on my part."

Anyway, here's a freebie pseudo-code:
C#:
totalCost = (  bagelBaseCost
             + (isWheatUpgrade ? wheatUpgradeCost : 0.0m)
             + (isEverythingUpgrade ? everythingUpgradeCost : 0.0m)
             + (isToastedOption ? toastCost : 0.0m)
             + (isCreamCheeseOption ? creamCheeseCost : 0.0m)
            )
            * numberOfBagels
            * (1.0m + (isDineIn ? dineInTaxRate : 0.0m))

The reason why the formula is so complicated is because you wanted everything to be a single formula like a mathematician or Excel jockey.

If you do things like a normal programmer, things look much simpler with this pseudo-code:
C#:
bagelCost = baseCost;
if (isWheatUpgrade)
    bagelCost += wheatUpgradeCost
else if (isEverythingUpgrade)
    bagelCost += everythingUpgradeCost

if (isToastedOption)
    bagelCost += toastedCost

if (isCreamCheeseOption)
    bagelCost += creamCheeseCost

taxRate = 1.0m
if (isDineIn)
    taxRate += dineInTaxRate

totalCost = numberOfBagels * bagelCost * taxRate

Good luck with the rest of your code. Clock is ticking...
 

Latest posts

Back
Top Bottom