Jump to content

quantity on numeric up down

Daniboi

hi so i am very new to event driven programming and have been set a task to do. In my program i have made I am using a numericUpDownBox to denote a quantity. My issue is that when i have nothing inside of the box it will count it will count it as one. So if i order nothing in the quantity but have an order like Small and Cotton it will still count 0 as one and put it through as £6.00 but if i get 1 its £12.00 can someone give me some help and point me in the right direction.

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TshirtForm

{

    

    public partial class Form1 : Form
    {

        //shirt sizes

        decimal sizeCost = 0.00m;
        const decimal extraSmall = 4.50m;
        const decimal Small = 5.00m;
        const decimal meduim = 5.50m;
        const decimal large = 6.00m;
        const decimal extraLarge = 7.00m;

        //colour

        string red;
        string blue;
        string white;
        string green;
        string purple;
        string yellow;
        string colour;

        //material

        decimal fabCost = 0.00m;
        const decimal cotton = 1.00m;
        const decimal lycra = 2.50m;
        

        //quantity

        int quanty = 0;

        //printing 



        const decimal printingCost = 2.00m;

        //misc

        decimal cost = 0;
        decimal totalCost1 = 0;
        decimal totalCost = 0;
        string surname = "";


        public Form1()
        {
            InitializeComponent();

        }

        private void radioButtonExtraLarge_CheckedChanged(object sender, EventArgs e)
        {
        
            sizeCost = extraLarge;

        }

        private void radioButtonMeduim_CheckedChanged(object sender, EventArgs e)
        {
            
            sizeCost = meduim;
        }

        private void radioButtonGreen_CheckedChanged(object sender, EventArgs e)
        {
            colour = green;
        }

        private void radioButtonBlue_CheckedChanged(object sender, EventArgs e)
        {
            colour = blue;
        }

        private void radioButtonExtraSmall_CheckedChanged(object sender, EventArgs e)
        {
          
            sizeCost = extraSmall;
        }

        private void radioButtonSmall_CheckedChanged(object sender, EventArgs e)
        {
            
            sizeCost = Small ;
        }

        private void radioButtonLarge_CheckedChanged(object sender, EventArgs e)
        {
           
            sizeCost = large;
        }

        private void radioButtonYellow_CheckedChanged(object sender, EventArgs e)
        {
            colour = yellow;
        }

        private void radioButtonPurple_CheckedChanged(object sender, EventArgs e)
        {
            colour = purple;
        }

        private void radioButtonWhite_CheckedChanged(object sender, EventArgs e)
        {
            colour = white;
        }

        private void radioButtonRed_CheckedChanged(object sender, EventArgs e)
        {
            colour = red;
        }


        private void radioButtonCotton_CheckedChanged(object sender, EventArgs e)
        {
            fabCost = cotton;
        }

        private void radioButtonLycra_CheckedChanged(object sender, EventArgs e)
        {
            fabCost = lycra;
        }


        private void radioButtonNo_CheckedChanged(object sender, EventArgs e)
        {
            
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            totalCost = printingCost;




        }


        private void buttonOrder_Click(object sender, EventArgs e)
        {
            totalCost = sizeCost * quanty; 
            totalCost1 = fabCost * quanty;


            //fix this
            if (!string.IsNullOrWhiteSpace(textBox1.Text))
            {
                cost = cost - 2.00m;
            }

            cost = fabCost + sizeCost + totalCost;

            labelDisplayCost.Text = cost.ToString("c");

            MessageBox.Show("The total cost is " + cost );
        }

        private void numericUpDownQuant_ValueChanged(object sender, EventArgs e)
        {
            quanty = Convert.ToByte(numericUpDownQuant.Value);
        }
    }
} 
Link to comment
Share on other sites

Link to post
Share on other sites

In computer language zero is an actual amount.
I dont know the language but can you set the variable at 1 and that being the 6$ ?

When i ask for more specs, don't expect me to know the answer!
I'm just helping YOU to help YOURSELF!
(The more info you give the easier it is for others to help you out!)

Not willing to capitulate to the ignorance of the masses!

Link to comment
Share on other sites

Link to post
Share on other sites

16 minutes ago, HanZie82 said:

In computer language zero is an actual amount.
I dont know the language but can you set the variable at 1 and that being the 6$ ?

Sorry its c#

Link to comment
Share on other sites

Link to post
Share on other sites

14 hours ago, Daniboi said:

Sorry its c#

Press F9 on the starting line of your code and step through it using F10 to see where it comes up with $12 and why.

That i the only way you an learn code, by debugging it.

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to comment
Share on other sites

Link to post
Share on other sites

17 hours ago, Daniboi said:

So if i order nothing in the quantity but have an order like Small and Cotton it will still count 0

Your whole explanation is quite blurry but from that line what i understand is when the numericUpDown is empty (not text) your still have a number. If that is really your problem then that is normal. the updown control consist of (to make it simple) 3 controls, a textbox, a panel and a updown control. When you think you change the value you are actually changing the text. Once the text is validated and considered valid it changes the property "Value" to the decimal (128 bits) value represented by that string. So clearing the text showing in the control wont do anything as the "Value" property will keep the last valid value.

Link to comment
Share on other sites

Link to post
Share on other sites

Quote

So if i order nothing in the quantity but have an order like Small and Cotton it will still count 0 as one and put it through as £6.00

 

cost = fabCost + sizeCost + totalCost;

Fabcost for cotton is 1, sizeCost for small is 5, and totalCost is 0. That's 6 even thought he quantity is 0, right? Maybe this is supposed to be a multiplication rather than addition since the costs should be for each item? 

 

However, with that being said I have no idea how quantity increasing by 1 changes the total to 12. Since:

fabcost will be 1 again, sizeCost = 5, and totalCost = 5 (since totalCost  = sizeCost * quanty). That would end up being 11, not 12. Unless you're adding totalCost1 to it somewhere, which I don't see. 

 

With that in mind, I recommend a breakpoint at your cost calculation. See what is actually going into the value it's coming up with. That or even just a

Console.WriteLine(fabCost + ":" + sizeCost + ":" + totalCost);

before the calculation. Post your results if you can. 

Link to comment
Share on other sites

Link to post
Share on other sites

On 3/2/2020 at 7:23 PM, HanZie82 said:

In computer language zero is an actual amount.
I dont know the language but can you set the variable at 1 and that being the 6$ ?

sure but i am doing multipcation by the quantity. If that was the case it should then still be £0 because 0 X 5 = 0

Link to comment
Share on other sites

Link to post
Share on other sites

28 minutes ago, Daniboi said:

sure but i am doing multipcation by the quantity. If that was the case it should then still be £0 because 0 X 5 = 0

You're calculating cost as:

Quote

fabCost + sizeCost + totalCost;

1 + 5 + (0*5) = 6. 

 

Also, how have you defined your numericUpDown? What are your initial, minimum, maximum values? 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×