I
i
#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<string.h>
char ch;
int n,m;
void main();
char check(int,int,char);
void cash(int,int,char);
void debit_card(int,int,char);
void creditcard(int no,int mo,char cho);
void clear(int,int,char);
void receipt(int,int);
struct ing
{
int co,s,c;
}ingr;
struct debit
{
int dc_n,p;
float bal;
}d[10];
struct credit
{
int cre;
float cl;
}ce[10];
void main()
{
/* struct ing
{
int co,s,c;
}ingr;
struct debit
{
int dc_n,p;
float bal;
}d[10];
struct credit
{
int cre;
float cl;
}ce[10];*/
FILE *fp;
char ch1,ch2;
int i,j;
j=1;
printf("\nFor Black Coffee\t\t Enter 'b'\nFor White Coffee\t\t Enter
'w'");
if(j==1)
{
fp=fopen("ingredient.dat","w");
scanf("%d%d%d",&ingr.co,&ingr.s,&ingr.c);
fwrite(fp,sizeof(struct ing),1,fp);
fclose(fp);
fp=fopen("debitCard.dat","w");
for(i=0;i<10;i++)
scanf("%d%d%f",&d.dc_n,&d.p,&d.bal);
fwrite(d,sizeof(struct ing),10,fp);
fclose(fp);
fp=fopen("creditCard.dat","w");
for(i=0;i<10;i++)
scanf("%d%f",&ce.cre,&ce.cl);
fwrite(ce,sizeof(struct credit),10,fp);
fclose(fp);
j++;
}
printf("\nFor Black Coffee\t\t Enter 'b'\nFor White Coffee\t\t Enter
'w'");
ch=getche();
if(ch=='b')
{
printf("\nEnter no.of Black Coffees");
scanf("%d",&n);
m=0;
}
else
if(ch=='w')
{
printf("\nEnter no.of White Coffees");
scanf("%d",&m);
}
ch2=check(n,m,ch);
if(ch2=='a')
{
print("\nEnter Mode of Payment\nFor Cash Enter 'c'\nFor debit card
Enter 'd'\nFor Credit card Enter 'r'");
ch1=getche();
if(ch1=='c')
{
cash(n,m,ch);
}
else
if(ch1=='d')
{
debit_card(n,m,ch);
}
else
if(ch1=='r')
{
creditcard(n,m,ch);
}
}
getch();
}
char check(int n6,int m6,char ch_6)
{
FILE *fp;
char g;
fp=fopen("ingredient.dat","r+t");
fread(&ingr,sizeof(struct ing),1,fp);
if(ch_6=='b')
{
if(ingr.co>=n6)
{
g='a';
return(g);
}
else
{
printf("\nThere is not enough coffee powder");
}
}
else
if(ch_6=='w')
{
if((ingr.co>=m6)&&(ingr.s>=m6)&&(ingr.c>=m6))
{
g='a';
return(g);
}
else
{
printf("\nThere is not enough coffee powder, sugar and creamer");
}
}
return(0);
}
void cash(int n1,int m1,char ch_1)
{
int k,l,o,sum=0;
FILE *fp;
if(ch_1=='b')
{
scanf("%d%d%d",&k,&l,&o);
while(sum!=(n1*6))
{
if((k==10)&&(k==20)&&(k==50)&&(k==100)&&(k==500)&&(k==1000))
{
printf("\nInvalid Cash.Give only 1,2 and 5 rupee coins");
scanf("%d",&k);
}
if((l==10)&&(l==20)&&(l==50)&&(l==100)&&(l==500)&&(l==1000))
{
printf("\nInvalid Cash.Give only 1,2 and 5 rupee coins");
scanf("%d",&l);
}
if((o==10)&&(o==20)&&(o==50)&&(o==100)&&(o==500)&&(o==1000))
{
printf("\nInvalid Cash.Give only 1,2 and 5 rupee coins");
scanf("%d",&o);
}
sum+=k+l+o;
}
if(sum!=0)
{
clear(n1,m1,ch_1);
receipt(n1,sum);
}
}
else if(ch_1=='w')
{
scanf("%d%d%d",&k,&l,&o);
while(sum!=(m1*10))
{
if((k==10)&&(k==20)&&(k==50)&&(k==100)&&(k==500)&&(k==1000))
{
printf("\nInvalid Cash.Give only 1,2 and 5 rupee coins");
scanf("%d",&k);
}
if((l==10)&&(l==20)&&(l==50)&&(l==100)&&(l==500)&&(l==1000))
{
printf("\nInvalid Cash.Give only 1,2 and 5 rupee coins");
scanf("%d",&l);
}
if((o==10)&&(o==20)&&(o==50)&&(o==100)&&(o==500)&&(o==1000))
{
printf("\nInvalid Cash.Give only 1,2 and 5 rupee coins");
scanf("%d",&o);
}
sum+=k+l+o;
}
if(sum!=0)
{
clear(n1,m1,ch_1);
receipt(m1,sum);
}
}
}
void debit_card(int n5,int m5,char ch_5)
{
FILE *fp;
int i,de,pin,j;
fp=fopen("debitCard.dat","r+t");
fread(&d[10],sizeof(struct debit),10,fp);
printf("\nEnter debit card number and pin number");
scanf("%d%d",&de,&pin);
for(i=0;i<sizeof(struct debit);i++)
{
if(ch_5=='b')
{
j=n5*6;
if((de==d.dc_n)&&(pin==d.p))
{
if(d.bal>j)
{
d.bal-=j;
fwrite(d,sizeof(struct debit),1,fp);
clear(n5,m5,ch_5);
receipt(n5,j);
}
else if(d.bal<0)
{
printf("\nBalance below zero");
}
else if(d.bal<j)
{
printf("\nThere is no enough money");
}
}
else
printf("\nIncorrect format");
}
else
if(ch_5=='w')
{
j=m5*10;
if((de==d.dc_n)&&(pin==d.p))
{
if(d.bal>j)
{
d.bal-=j;
fwrite(d,sizeof(d),1,fp);
clear(n5,m5,ch_5);
receipt(n5,j);
}
else if(d.bal<0)
{
printf("\nBalance below zero");
}
else if(d.bal<j)
{
printf("\nThere is no enough money");
}
}
else
printf("\nIncorrect format");
}
fclose(fp);
}
void creditcard(int n2,int m2,char ch_2)
{
FILE *fp;
int i,j,cd;
fp=fopen("creditCard.dat","r+t");
fread(&ce[10],sizeof(struct credit),10,fp);
printf("\nEnter the credit card number");
scanf("%d",&cd);
for(i=0;i<sizeof(struct credit);i++)
{
if(ch=='b')
{
j=n2*6;
if(ce.cre==cd)
{
if(ce.cl>j)
{
clear(n2,m2,ch_2);
receipt(n2,j);
}
else
printf("\nOver Credit Limit");
}
else
printf("\nIncorrect Format");
}
else
if(ch=='w')
{
j=m2*10;
if(ce.cre==cd)
{
if(ce.cl>j)
{
clear(n2,m2,ch_2);
receipt(m2,j);
}
else
{
printf("\nOver Credit Limit");
}
}
else
{
printf("\nIncorrect format");
}
}
}
fclose(fp);
}
void clear(int n3,int m3,char ch_3)
{
FILE *fp;
fp=fopen("ingredient.dat","r+t");
if(ch_3=='b')
{
fread(&ingr,sizeof(struct ing),1,fp);
ingr.co-=n3;
fwrite(ingr,sizeof(struct ing),1,fp);
printf("\nCoffee served");
fclose(fp);
}
else
if(ch_3=='w')
{
fread(&ingr,sizeof(struct ing),1,fp);
ingr.co-=m3;
ingr.sr-=m3;
ingr.cr-=m3;
fwrite(ingr,sizeof(struct ing),1,fp);
printf("\nCoffee served");
fclose(fp);
}
}
void receipt(int n4,int j1)
{
char ch3;
printf("\n****************************RECEIPT**********************************");
printf("\nThe Number of Coffees %d",n4);
printf("\nTotal amount of money %f",j1);
printf("\nDo you want to continue order coffee?y/n");
ch3=getche();
if(ch3=='y')
{
main();
}
}
}
I got three errors in this program which i can't solve. Anybody helps
me to solve these errors.
Errors are:
1.Declaration is not allowed here
2.Declaration syntax error.
3.Declaration missing;
#include<conio.h>
#include<process.h>
#include<string.h>
char ch;
int n,m;
void main();
char check(int,int,char);
void cash(int,int,char);
void debit_card(int,int,char);
void creditcard(int no,int mo,char cho);
void clear(int,int,char);
void receipt(int,int);
struct ing
{
int co,s,c;
}ingr;
struct debit
{
int dc_n,p;
float bal;
}d[10];
struct credit
{
int cre;
float cl;
}ce[10];
void main()
{
/* struct ing
{
int co,s,c;
}ingr;
struct debit
{
int dc_n,p;
float bal;
}d[10];
struct credit
{
int cre;
float cl;
}ce[10];*/
FILE *fp;
char ch1,ch2;
int i,j;
j=1;
printf("\nFor Black Coffee\t\t Enter 'b'\nFor White Coffee\t\t Enter
'w'");
if(j==1)
{
fp=fopen("ingredient.dat","w");
scanf("%d%d%d",&ingr.co,&ingr.s,&ingr.c);
fwrite(fp,sizeof(struct ing),1,fp);
fclose(fp);
fp=fopen("debitCard.dat","w");
for(i=0;i<10;i++)
scanf("%d%d%f",&d.dc_n,&d.p,&d.bal);
fwrite(d,sizeof(struct ing),10,fp);
fclose(fp);
fp=fopen("creditCard.dat","w");
for(i=0;i<10;i++)
scanf("%d%f",&ce.cre,&ce.cl);
fwrite(ce,sizeof(struct credit),10,fp);
fclose(fp);
j++;
}
printf("\nFor Black Coffee\t\t Enter 'b'\nFor White Coffee\t\t Enter
'w'");
ch=getche();
if(ch=='b')
{
printf("\nEnter no.of Black Coffees");
scanf("%d",&n);
m=0;
}
else
if(ch=='w')
{
printf("\nEnter no.of White Coffees");
scanf("%d",&m);
}
ch2=check(n,m,ch);
if(ch2=='a')
{
print("\nEnter Mode of Payment\nFor Cash Enter 'c'\nFor debit card
Enter 'd'\nFor Credit card Enter 'r'");
ch1=getche();
if(ch1=='c')
{
cash(n,m,ch);
}
else
if(ch1=='d')
{
debit_card(n,m,ch);
}
else
if(ch1=='r')
{
creditcard(n,m,ch);
}
}
getch();
}
char check(int n6,int m6,char ch_6)
{
FILE *fp;
char g;
fp=fopen("ingredient.dat","r+t");
fread(&ingr,sizeof(struct ing),1,fp);
if(ch_6=='b')
{
if(ingr.co>=n6)
{
g='a';
return(g);
}
else
{
printf("\nThere is not enough coffee powder");
}
}
else
if(ch_6=='w')
{
if((ingr.co>=m6)&&(ingr.s>=m6)&&(ingr.c>=m6))
{
g='a';
return(g);
}
else
{
printf("\nThere is not enough coffee powder, sugar and creamer");
}
}
return(0);
}
void cash(int n1,int m1,char ch_1)
{
int k,l,o,sum=0;
FILE *fp;
if(ch_1=='b')
{
scanf("%d%d%d",&k,&l,&o);
while(sum!=(n1*6))
{
if((k==10)&&(k==20)&&(k==50)&&(k==100)&&(k==500)&&(k==1000))
{
printf("\nInvalid Cash.Give only 1,2 and 5 rupee coins");
scanf("%d",&k);
}
if((l==10)&&(l==20)&&(l==50)&&(l==100)&&(l==500)&&(l==1000))
{
printf("\nInvalid Cash.Give only 1,2 and 5 rupee coins");
scanf("%d",&l);
}
if((o==10)&&(o==20)&&(o==50)&&(o==100)&&(o==500)&&(o==1000))
{
printf("\nInvalid Cash.Give only 1,2 and 5 rupee coins");
scanf("%d",&o);
}
sum+=k+l+o;
}
if(sum!=0)
{
clear(n1,m1,ch_1);
receipt(n1,sum);
}
}
else if(ch_1=='w')
{
scanf("%d%d%d",&k,&l,&o);
while(sum!=(m1*10))
{
if((k==10)&&(k==20)&&(k==50)&&(k==100)&&(k==500)&&(k==1000))
{
printf("\nInvalid Cash.Give only 1,2 and 5 rupee coins");
scanf("%d",&k);
}
if((l==10)&&(l==20)&&(l==50)&&(l==100)&&(l==500)&&(l==1000))
{
printf("\nInvalid Cash.Give only 1,2 and 5 rupee coins");
scanf("%d",&l);
}
if((o==10)&&(o==20)&&(o==50)&&(o==100)&&(o==500)&&(o==1000))
{
printf("\nInvalid Cash.Give only 1,2 and 5 rupee coins");
scanf("%d",&o);
}
sum+=k+l+o;
}
if(sum!=0)
{
clear(n1,m1,ch_1);
receipt(m1,sum);
}
}
}
void debit_card(int n5,int m5,char ch_5)
{
FILE *fp;
int i,de,pin,j;
fp=fopen("debitCard.dat","r+t");
fread(&d[10],sizeof(struct debit),10,fp);
printf("\nEnter debit card number and pin number");
scanf("%d%d",&de,&pin);
for(i=0;i<sizeof(struct debit);i++)
{
if(ch_5=='b')
{
j=n5*6;
if((de==d.dc_n)&&(pin==d.p))
{
if(d.bal>j)
{
d.bal-=j;
fwrite(d,sizeof(struct debit),1,fp);
clear(n5,m5,ch_5);
receipt(n5,j);
}
else if(d.bal<0)
{
printf("\nBalance below zero");
}
else if(d.bal<j)
{
printf("\nThere is no enough money");
}
}
else
printf("\nIncorrect format");
}
else
if(ch_5=='w')
{
j=m5*10;
if((de==d.dc_n)&&(pin==d.p))
{
if(d.bal>j)
{
d.bal-=j;
fwrite(d,sizeof(d),1,fp);
clear(n5,m5,ch_5);
receipt(n5,j);
}
else if(d.bal<0)
{
printf("\nBalance below zero");
}
else if(d.bal<j)
{
printf("\nThere is no enough money");
}
}
else
printf("\nIncorrect format");
}
fclose(fp);
}
void creditcard(int n2,int m2,char ch_2)
{
FILE *fp;
int i,j,cd;
fp=fopen("creditCard.dat","r+t");
fread(&ce[10],sizeof(struct credit),10,fp);
printf("\nEnter the credit card number");
scanf("%d",&cd);
for(i=0;i<sizeof(struct credit);i++)
{
if(ch=='b')
{
j=n2*6;
if(ce.cre==cd)
{
if(ce.cl>j)
{
clear(n2,m2,ch_2);
receipt(n2,j);
}
else
printf("\nOver Credit Limit");
}
else
printf("\nIncorrect Format");
}
else
if(ch=='w')
{
j=m2*10;
if(ce.cre==cd)
{
if(ce.cl>j)
{
clear(n2,m2,ch_2);
receipt(m2,j);
}
else
{
printf("\nOver Credit Limit");
}
}
else
{
printf("\nIncorrect format");
}
}
}
fclose(fp);
}
void clear(int n3,int m3,char ch_3)
{
FILE *fp;
fp=fopen("ingredient.dat","r+t");
if(ch_3=='b')
{
fread(&ingr,sizeof(struct ing),1,fp);
ingr.co-=n3;
fwrite(ingr,sizeof(struct ing),1,fp);
printf("\nCoffee served");
fclose(fp);
}
else
if(ch_3=='w')
{
fread(&ingr,sizeof(struct ing),1,fp);
ingr.co-=m3;
ingr.sr-=m3;
ingr.cr-=m3;
fwrite(ingr,sizeof(struct ing),1,fp);
printf("\nCoffee served");
fclose(fp);
}
}
void receipt(int n4,int j1)
{
char ch3;
printf("\n****************************RECEIPT**********************************");
printf("\nThe Number of Coffees %d",n4);
printf("\nTotal amount of money %f",j1);
printf("\nDo you want to continue order coffee?y/n");
ch3=getche();
if(ch3=='y')
{
main();
}
}
}
I got three errors in this program which i can't solve. Anybody helps
me to solve these errors.
Errors are:
1.Declaration is not allowed here
2.Declaration syntax error.
3.Declaration missing;