Click here to Skip to main content
15,887,415 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
in my code when i check my checkboxes the textbox beside it enables so when i add the values together in the textboxes using an array it keeps on giving me an exception warning saying input string format not correct


What I have tried:

const double Price_Friedrice = 200;
        const double Price_Jollofrice = 200;
        const double Price_Spags = 200;
        const double Price_Beans = 200;
        const double Price_Fries = 600;
        const double Price_Salad = 100;
        const double Price_Chicken= 300;
        const double Price_Plantain = 50;
        const double Price_Egg = 50;
        const double Price_Fish = 100;
        const double Price_Cocorice = 300;
        const double Price_Turkey = 500;
        const double Price_Moin = 50;
        const double Price_breadandegg = 200;
        const double Price_ewagee = 200;
        const double Price_Whiterice = 200;
        const double Price_Ofada = 200;
        const double Price_Gizzard = 50;
        const double Price_Bole = 500;
        const double Price_Burritos = 500;
        const double Price_Smallchops = 500;
        const double Price_Pizza = 600;
        const double Price_Sharwama = 600;
        const double Price_Suya = 400;
        const double Price_Waffles = 500;
        const double Price_Water = 50;
        const double Price_Exotic = 400;
        const double Price_Coke = 120;
        const double Price_Fanta = 120;
        const double Price_Pepsi = 120;
        const double Price_Mirinda = 100;
        const double Price_Slush = 200;
        const double Price_Juice = 250;
        const double Price_Sobo = 100;
        const double Price_Eba = 100;
        const double Price_Poundoyam = 100;
        const double Price_Semo = 50;
        const double Price_Egusi = 0;
        const double Price_Vegetable = 0;
        const double Price_Ewedu = 0;
        const double Price_Okra = 0;
        const double Price_WhiteSoup = 0;
        const double Tax_rate = 20;

        double  iTax, iSubtotal, iTotal;

private void Total_btn_Click(object sender, EventArgs e)
       {
           double[] cost_of_Item = new double[41];
           cost_of_Item[0] = Convert.ToDouble(friedricetxt.Text) * Price_Friedrice;
           cost_of_Item[1] = Convert.ToDouble(jolloftxt.Text) * Price_Jollofrice;
           cost_of_Item[2] = Convert.ToDouble(spagstxt.Text) * Price_Spags;
           cost_of_Item[3] = Convert.ToDouble(Beanstxt.Text) * Price_Beans;
           cost_of_Item[4] = Convert.ToDouble(Fries_txt.Text) * Price_Fries;
           cost_of_Item[5] = Convert.ToDouble(salad_txt.Text) * Price_Salad;
           cost_of_Item[6] = Convert.ToDouble(chicken_txt.Text) * Price_Chicken;
           cost_of_Item[7] = Convert.ToDouble(plantain_txt.Text) * Price_Plantain;
           cost_of_Item[8] = Convert.ToDouble(Egg_txt.Text) * Price_Egg;
           cost_of_Item[9] = Convert.ToDouble(fish_txt.Text) * Price_Fish;
           cost_of_Item[10] = Convert.ToDouble(Cocorice_txt.Text) * Price_Cocorice;
           cost_of_Item[11] = Convert.ToDouble(Turkey_txt.Text) * Price_Turkey;
           cost_of_Item[12] = Convert.ToDouble(moin_txt.Text) * Price_Moin;
           cost_of_Item[13] = Convert.ToDouble(Breadegg_txt.Text) * Price_breadandegg;
           cost_of_Item[14] = Convert.ToDouble(whiterice_txt.Text) * Price_Whiterice;
           cost_of_Item[15] = Convert.ToDouble(Ofada_txt.Text) * Price_Ofada;
           cost_of_Item[16] = Convert.ToDouble(Gizzard_txt.Text) * Price_Gizzard;
           cost_of_Item[17] = Convert.ToDouble(Bole_txt.Text) * Price_Bole;
           cost_of_Item[18] = Convert.ToDouble(Burritos_txt.Text) * Price_Burritos;
           cost_of_Item[19] = Convert.ToDouble(Smallchops_txt.Text) * Price_Smallchops;
           cost_of_Item[20] = Convert.ToDouble(pizza_txt.Text) * Price_Pizza;
           cost_of_Item[21] = Convert.ToDouble(Sharwama_txt.Text) * Price_Sharwama;
           cost_of_Item[22] = Convert.ToDouble(Suya_txt.Text) * Price_Suya;
           cost_of_Item[23] = Convert.ToDouble(Waffles_txt.Text) * Price_Waffles;
           cost_of_Item[24] = Convert.ToDouble(Water_txt.Text) * Price_Water;
           cost_of_Item[25] = Convert.ToDouble(Exotic_txt.Text) * Price_Exotic;
           cost_of_Item[26] = Convert.ToDouble(Coke_txt.Text) * Price_Coke;
           cost_of_Item[27] = Convert.ToDouble(Fanta_txt.Text) * Price_Fanta;
           cost_of_Item[28] = Convert.ToDouble(Pepsi_txt.Text) * Price_Pepsi;
           cost_of_Item[29] = Convert.ToDouble(Mirinda_txt.Text) * Price_Mirinda;
           cost_of_Item[30] = Convert.ToDouble(Slush_txt.Text) * Price_Slush;
           cost_of_Item[31] = Convert.ToDouble(Fuitjuicetxt.Text) * Price_Juice;
           cost_of_Item[32] = Convert.ToDouble(Sobo_txt.Text) * Price_Sobo;
           cost_of_Item[33] = Convert.ToDouble(eba_txt.Text) * Price_Eba;
           cost_of_Item[34] = Convert.ToDouble(poundo_txt.Text) * Price_Poundoyam;
           cost_of_Item[35] = Convert.ToDouble(Semo_txt.Text) * Price_Semo;
           cost_of_Item[36] = Convert.ToDouble(egusi_txt.Text) * Price_Egusi;
           cost_of_Item[37] = Convert.ToDouble(Vegetable_txt.Text) * Price_Vegetable;
           cost_of_Item[38] = Convert.ToDouble(Ewedu_txt.Text) * Price_Ewedu;
           cost_of_Item[39] = Convert.ToDouble(Okra_txt.Text) * Price_Okra;
           cost_of_Item[40] = Convert.ToDouble(Whitesoup_txt.Text) * Price_WhiteSoup;

           double cost, Change;
           if (method_payment.Text == "Cash")
           {
               iSubtotal = cost_of_Item[0] + cost_of_Item[1] + cost_of_Item[2] + cost_of_Item[3] + cost_of_Item[4] + cost_of_Item[5] +
               cost_of_Item[6] + cost_of_Item[7] + cost_of_Item[8] + cost_of_Item[9] + cost_of_Item[10] + cost_of_Item[11] + cost_of_Item[12]
               + cost_of_Item[13] + cost_of_Item[14] + cost_of_Item[15] + cost_of_Item[16] + cost_of_Item[17] + cost_of_Item[18] + cost_of_Item[19]
               + cost_of_Item[20] + cost_of_Item[21] + cost_of_Item[22] + cost_of_Item[23] + cost_of_Item[24] + cost_of_Item[25] + cost_of_Item[26]
               + cost_of_Item[27] + cost_of_Item[28] + cost_of_Item[29] + cost_of_Item[30] + cost_of_Item[31] + cost_of_Item[32] + cost_of_Item[33]
               + cost_of_Item[34] + cost_of_Item[35] + cost_of_Item[36] + cost_of_Item[37] + cost_of_Item[38] + cost_of_Item[39] + cost_of_Item[40];

               Subtotlbl.Text = Convert.ToString(iSubtotal);
               iTax = (iSubtotal * Tax_rate)/100;
               Taxlbl.Text = Convert.ToString(iTax);
               iTotal = (iSubtotal + iTax);
               Totallbl.Text = Convert.ToString(iTotal);
               Change = Convert.ToDouble(method_payment.Text);
               cost = Change - (iTotal);
Posted
Updated 23-Mar-17 21:07pm
Comments
Richard MacCutchan 24-Mar-17 5:26am    
Do not use double types for financial applications, you will get incorrect values and your customers may want to sue you.

1 solution

Means you are trying to convert a string which is not in a valid numeric format.
use Double.TryParse Method (System)[^]

ex:
double friedrice;
            if( double.TryParse(friedricetxt.Text, out value))
            {
                 cost_of_Item[0] = friedrice * Price_Friedrice;
            }
            else
            {
                 // show the error message  for entering  non numeric value format
            }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900