c# - Always getting to the else part in the if statement -


i having problem getting code work. whenever input 249 or lower, works should. else gets me else statement:

using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks;  namespace ilab02 {     class program     {         static void main(string[] args)         {             double salesamount, shippingamount;             salesamount = 0.00;             shippingamount = 0.00;             console.writeline("what total amount of sales?");             salesamount = convert.todouble(console.readline());             if (salesamount > 5000.00)             {                 shippingamount = 20.00;             }             if (salesamount > 1000.00 && salesamount <= 5000.00)             {                 shippingamount = 15.00;             }             if (salesamount > 500.00 && salesamount<=1000.00)             {                 shippingamount = 10.00;             }             if (salesamount > 250.00 && salesamount <=500.00)             {                 shippingamount = 8.00;             }             if (salesamount > 0.00 && salesamount <=250.00)             {                 shippingamount = 5.00;             }             else             {                 shippingamount = 0.00;                 console.writeline("error incorrect input!");             }             console.writeline("total sales amount {0:c}",salesamount);             console.writeline("shipping charges {0:c}", shippingamount);             console.readline();         }     } } 

you need use else if. code check first if, if that's not true goes straight else it's supposed , other conditions never checked:

    if (salesamount > 5000.00)     {         shippingamount = 20.00;     }     else if (salesamount > 1000.00 && salesamount <= 5000.00)     {         shippingamount = 15.00;     }     else if (salesamount > 500.00 && salesamount<=1000.00)     {         shippingamount = 10.00;     }     else if (salesamount > 250.00 && salesamount <=500.00)     {         shippingamount = 8.00;     }     else if (salesamount > 0.00 && salesamount <=250.00)     {         shippingamount = 5.00;     }     else     {         shippingamount = 0.00;         console.writeline("error incorrect input!");     } 

edit: little sidenode, title should problem. example "if-condition not reached".


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -