c# when pressing a button add totals together [closed]

I would advise making the “unleaded”, “Diesel”, “Premium” options RadioButtons instead of Buttons and bind them under a container like Panel. So, when the user presses the “buttonTotal” the program will check which RadioButton is checked and then calculate the corresponding value.

private void btnTotal_Click(object sender, EventArgs e)
{
        double totalPrice = 0;
        if(unleadedRadioButton.Checked)
        {
             totalPrice = lblDailyPrice * lblTotalLitresEntered * unleadedValue;
        }
        else if (dieselRadioButton.Checked)
        {
             totalPrice = lblDailyPrice * lblTotalLitresEntered * dieselValue;
        }
        else if (premiumRadioButton.Checked)
        {
             totalPrice = lblDailyPrice * lblTotalLitresEntered * premiumValue;
        }
}

Leave a Comment