Home > Net >  Visual studio Multiply CheckBox with NumericUpDown
Visual studio Multiply CheckBox with NumericUpDown

Time:12-11

Ok so I have multiple checkbox's with a baseprice but I need to multiply a numericupdown so this would be the users input.

I thought this would work

    if (potatoes.Checked)
    {
    baseprice * NumericUpDown1.Value;
    }

but it does not :( any help? im using windows form apps c#

Say the ``baseprice for my first check box is $1.91 I want it to multipy the NumericUpDown with what the user inputs. to txtTotal.Text

Code for cs

using System;
using System.Windows.Forms;
namespace IceCreamMelts
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }
        /// <summary>
        /// Validates user input and returns true if valid
        /// </summary>
        /// <returns></returns>
        private bool vaildInputs()
        {
            //At least one falvour should be selects
            if (cbChocolate.Checked == false && cbStrawberry.Checked == false &&
            cbVanilla.Checked == false)
            {
                MessageBox.Show("Select at least one flavour.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
            return true;
        }
        private void btnOrderNow_Click(object sender, EventArgs e)
        {
            //if valid input, process the order
            if (vaildInputs())
            {
                //Calculate baseprice based on Scoop
                double baseprice = 0.0;
                if (tomatoes.Checked)
                {
                    baseprice = 1.91;
                }
                else if (peppers.Checked)
                {
                    baseprice = 2.32;
                }
                else if (onions.Checked)
                {
                    baseprice = 1.05;
                }
                else if (potatoes.Checked)
                {
                    baseprice = 1.50;
                }
                //Add price for toppings
                if (tomatoes.Checked)
                {
                    baseprice  = 0.50;
                }
                if (peppers.Checked)
                {
                    baseprice  = 0.50;
                }
                if (onions.Checked)
                {
                    baseprice  = 0.50;
                }
                if (potatoes.Checked)
                {
                    (baseprice * NumericUpDown1.Value).ToString();
                }
                //Show the price form
                frmShowPrice showprice = new frmShowPrice();
                showprice.SubTotal = baseprice;
                showprice.ShowDialog();
                //Reset the form, once show price form closed
                cbChocolate.Checked = false;
                cbStrawberry.Checked = false;
                cbVanilla.Checked = false;
                rbOneScoop.Checked = true;
            }
        }
        private void btnExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
        }
        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
        }
    }
}

CodePudding user response:

also, if this is not a property, you are missing a an equal sign,

if (potatoes.Checked) { baseprice =* NumericUpDown1.Value; }

CodePudding user response:

if this is c# property, then you need a return value, if not where is the equal sign for the result

  •  Tags:  
  • c#
  • Related