may i ask whats wrong with my if statement?

#include <iostream.h>
#include <stdlib.h>

main()
{

char name[20];

double sales,com; //com is commission

cout<<"\n Input name and sales " ;
cin>>name>>sales;

if (sales<15000)com=0;//if sales is below 15t com is 0
if (sales<25000)com=sales-15000*.1+1500;
//if sales between 15t to 25t com is 1500+10% of sales that exceeds 15000
if (sales>25000)com=sales-25000*.1+1500;
//if sales is 25t up com is 3000+10% of sales that exceeds 15000

cout<<"\n the commission is " <<com;


system("PAUSE");
return 0;
}

it runs but i am not sure if the output is right... thanks in advance...
Last edited on
if sales<15000 then also sales<25000, since 15000<25000. You're missing what happens if sales==25000,
Use
1
2
3
4
5
6
if (sales<15000)
    //...
else if (sales<25000)
    //...
else
    //... 
sir helios i try this but parse error before = sign. i am just new with c programming pls help. thanks in advance.

if (sales<=15000)com=0;

else if (15000<25000)com=(sales-15000)*.1+1500;
else (sales>25000)com=sales-25000*.1+1500;
Look closely at my post. Does it say else (sales>25000) or else? It just says "else", doesn't it? else statements don't allow a condition because it wouldn't make sense. It's just the part that is executed if all the other conditions were false.
As an aside, prefer this style
1
2
if (condition)
    statement;
over this style
 
if (condition) statement;

The first one improves readability and doesn't give the more experienced programmers the desire to smack you over the head with a C++ manual, so it's a win-win situation.
Last edited on
if (sales<15000)com=0;

if (sales>15000)
com=(sales-15000)*.1+1500;
if (sales>25000)
com=(sales-25000)*.1+3000;

sir helios thanks a lot for your suggestion i make it... more power to these forum i am learning... thank a lot.
Hi,
I am Rammohan from Bangalore and working as a Technical lead in big IT firm .
Solution for your answer is follows:


The way you have coded is wrong. Compiler cannot choose the sales value is in which level. You need to write the code as follows:

if (sales<=15000)
Commission=0;
else if (15000<25000)
Commission = (sales-15000)*.1+1500;
else (sales>25000)
Commission = sales-25000*.1+1500;
____________________
Regards,
Rammohan Alampally,
rammohan@india.com
Technical Lead,
Bangalore, India.
www.FindSyntax.com -> Worlds first Web based Windows O/S is a Brain Chaild of Rammohan
Oh my god, what the hack should that be? It isn't april the 1st on my calendar. And the statement
else if (15000<25000)
is a code joke at best, and not even a funny one. By the way, this forum doesn't support signatures, for which I'm quite grateful. So please stop you futile attempt to create attention by putting them in manually.
Topic archived. No new replies allowed.