please run this simple program......

why wont this work ?

i tried it first with if...else

/*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

#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...

So many errors. Your semicolons were in the wrong place, you have the incorrect definition of using greater-than/less-than symbols, you should switch to the header, <iostream> without the ".h". You also need to make the main function, "int main()", not just main.

Well, there may be errors, but I got your program working. Take a look at the things I fixed in comparison to your own code. Thanks!

#include <conio.h>
#include <iostream>
using namespace std;
int 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(sales<50) 
		cout << "\n 5% commission " << total_sales * 0.05;
	else if(sales<75) 
		cout << "\n 10% commission " << total_sales * 0.10;
	else if(sales<100)
		cout << "\n 20% commission " << total_sales * 0.20;
	getch();

}

cheers

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.