Anyone know how to get out from loop. I mean when we press -1 value, it stops.
#include<stdio.h>
#define CD 0.05
#define LD 0.06
#define MD 0.07
float Get_disc(char b,float c);
float Discount_amt(float z,float x);
void Net_amt(float n,float m);
void Display(float r, float s);
int main()
{
int a=0;
char b,C,L,M;
float c;
while(a!=-1)
{
printf("Customer no: ");
scanf("%d",&a);
printf("Enter department(C,L,M): ");
fflush (stdin);
scanf("%c",&b);
if(b=='C'||b=='L'||b=='M')
{
float p, q;
printf("Enter amount:RM");
scanf("%f",&c);
p=Get_disc(b,c);
q=Discount_amt(c,p);
Net_amt(c,q);
}
else
{
printf("Invalid\n");
}
}
system("pause");
return 0;
}
float Get_disc(char b,float c)
{
int p;
if(b=='C')
{
if(c>200)
p=(2*CD)*100;
else
p=CD*100;
}
else if(b=='L')
{
if(c>200)
p=2*LD*100;
else
p=LD*100;
}
else
{
if(c>200)
p=(0.08+MD)*100;
else
p=MD*100;
}
printf("This cust will get %d %% discount\n",p);
return p;
}
float Discount_amt(float z,float x)
{
float v;
v=(z*(x/100));
return v;
}
void Net_amt(float n,float m)
{
float g;
g=n-m;
Display(m,g);
return;
}
void Display(float r, float s)
{
printf("Discount amount:%.2f\nNet amount to pay:%.2f\n\n",r,s);
}