c newbie c newbie - 3 years ago 90
C Question

if condition errors in my C code

this my code
i wanna when i put a price between 2000 and 5000 they make a promotion with 5%
and when i put price more than 5000 they make only 10%

so please help me to find the problem and thanks

#include <stdio.h>
#include <conio.h>

main ()
{
int e;
float b,o;
printf("le prix total en DT est : \t");
scanf("%d", &e);
if ( e < 1999 ) {
printf("il n y pas de remise \n");
}
else if ( e > 5000 ) {
printf("il y a un remise avec 10% \n");
o = e * (1 - 0.05 ) ;
printf("le prix avant le remise est %d DT et apres le remise est %2.f DT\n",e,o);
}
else if ( 2000 < e < 5000 ) {
printf("il y a un reemise avec 5 % \n");
b = e * (1 - 0.1 ) ;
printf("le prix avant le remise est %d DT et apres le remise est %2.f DT\n",e,b);

}

getch();
return 0;
}

Answer Source
if(e>=2000 && e<=5000) 

Change your last if condition to the one I mentioned above.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download