if else switch... why wont this program work ?

try running this simple program....

why wont this work ?

i tried it first with if...else
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*why will this program not run? what did i do wrong with the if else statements/conditions ?*/



#include <conio.h>
#include <iostream.h>
main()
{
	double sales, sales_amount, quantity, total_sales, vat;
   total_sales = sales + vat;
   vat = 0.175*sales;

   cout << "\nTotal Sales = sales amount * quantity\n";  endl;
   cout << "\nEnter the sales amount\n";
   cin >>  sales_amount;
   cout << "\nEnter the quantity\n" ;
   cin >>  quantity ;
   sales = (sales_amount * quantity);
   cout << "\n" << sales_amount << "  *  " << quantity << " = " << sales << "\n";
   cout << "\n" << "Sales is: \t" << sales << "\n";
   cout << "\ntotal sales inc VAT is: \t" << (sales + 0.175*sales) << "\n";

   	if (sales < 25) cout << "\nNo commission";                                         //<-------------why will this not run?
      else if (50 > sales < 25) cout << "\n 5% commission   " << total_sales * 0.05;
      else if (75>sales<51) cout << "\n 10% commission    "; << total_sales * 0.10;
      else if (100>sales<76)cout << "\n 20% commission"; << total_sales * 0.20;
      else cout << "20% commission" ;
   getch();

   }


i tried it with a switch statement

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <conio.h>
#include <iostream.h>
main()
{
	double sales, sales_amount, quantity, total_sales, vat;
   total_sales = sales + vat;
   vat = 0.175*sales;

   cout << "\nTotal Sales = sales amount * quantity\n";  endl;
   cout << "\nEnter the sales amount\n";
   cin >>  sales_amount;
   cout << "\nEnter the quantity\n" ;
   cin >>  quantity ;
   sales = (sales_amount * quantity);
   cout << "\n" << sales_amount << "  *  " << quantity << " = " << sales << "\n";
   cout << "\n" << "Sales is: \t" << sales << "\n";
   cout << "\ntotal sales inc VAT is: \t" << (sales + 0.175*sales) << "\n";

   switch(sales) {
   	case <25:
      	cout << "\nNo commission";
         break;
      case 50 > sales < 25:
         cout << "\n 5% commission   " << total_sales * 0.05;
         break;
      case 75 > sales < 51:
      	cout << "\n 10% commission    "; << total_sales * 0.10;
      case 100 > sales < 76:
      	cout << "\n 20% commission"; << total_sales * 0.20;
      default:
      	cout << "\n 20% commission";
   }
   getch();
}


someone help me out please...
You cannot do what you are trying to do with a switch. It won't work. You have to use the if statements, but you'll need to fix those conditions. 50 > sales < 25 is invalid (besides not being mathematically possible), among other things; it should (probably) be sales < 50 && sales > 25.
thanks
Topic archived. No new replies allowed.