467,223 Members | 1,400 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,223 developers. It's quick & easy.

error correcting

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[i].dc_n,&d[i].p,&d[i].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[i].cre,&ce[i].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[i].dc_n)&&(pin==d[i].p))
{
if(d[i].bal>j)
{
d[i].bal-=j;
fwrite(d,sizeof(struct debit),1,fp);
clear(n5,m5,ch_5);
receipt(n5,j);
}
else if(d[i].bal<0)
{
printf("\nBalance below zero");
}
else if(d[i].bal<j)
{
printf("\nThere is no enough money");
}
}
else
printf("\nIncorrect format");
}
else
if(ch_5=='w')
{
j=m5*10;
if((de==d[i].dc_n)&&(pin==d[i].p))
{
if(d[i].bal>j)
{
d[i].bal-=j;
fwrite(d,sizeof(d),1,fp);
clear(n5,m5,ch_5);
receipt(n5,j);
}
else if(d[i].bal<0)
{
printf("\nBalance below zero");
}
else if(d[i].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[i].cre==cd)
{
if(ce[i].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[i].cre==cd)
{
if(ce[i].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;

May 2 '07 #1
  • viewed: 2608
Share:
9 Replies
On 1 May 2007 23:03:51 -0700 in comp.lang.c++, i
<im*********@yahoo.co.inwrote,
>Errors are:
1.Declaration is not allowed here
Where?

May 2 '07 #2
"i" <im*********@yahoo.co.inwrote in message
news:11**********************@h2g2000hsg.googlegro ups.com...
#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[i].dc_n,&d[i].p,&d[i].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[i].cre,&ce[i].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[i].dc_n)&&(pin==d[i].p))
{
if(d[i].bal>j)
{
d[i].bal-=j;
fwrite(d,sizeof(struct debit),1,fp);
clear(n5,m5,ch_5);
receipt(n5,j);
}
else if(d[i].bal<0)
{
printf("\nBalance below zero");
}
else if(d[i].bal<j)
{
printf("\nThere is no enough money");
}
}
else
printf("\nIncorrect format");
}
else
if(ch_5=='w')
{
j=m5*10;
if((de==d[i].dc_n)&&(pin==d[i].p))
{
if(d[i].bal>j)
{
d[i].bal-=j;
fwrite(d,sizeof(d),1,fp);
clear(n5,m5,ch_5);
receipt(n5,j);
}
else if(d[i].bal<0)
{
printf("\nBalance below zero");
}
else if(d[i].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[i].cre==cd)
{
if(ce[i].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[i].cre==cd)
{
if(ce[i].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;
void main()
warning C4326: return type of 'main' should be 'int' instead of 'void'
Should be
int main()

ch=getche();
warning C4244: '=' : conversion from 'int' to 'char', possible loss of data
Okay, that one is livable. I don't know why it returns an int when it
doesn't return an error code (no -1 or anything I can see). int ch; may be
better but *shrug*

print("\nEnter Mode of Payment\nFor Cash Enter 'c'\nFor debit card Enter
'd'\nFor Credit card Enter 'r'");
error C3861: 'print': identifier not found, even with argument-dependent
lookup
I'm sure you meant printf here.

ch1=getche();
warning C4244: '=' : conversion from 'int' to 'char', possible loss of data
Same as before. Ignore, cast or int ch1.

void creditcard(int n2,int m2,char ch_2)
'creditcard' : local function definitions are illegal
Hmm, what? Oh, you're missing a } somewhere so it htinks you're still
inside a function, in this case the one that starts
void debit_card(int n5,int m5,char ch_5)
{
so debit_card is missing a ending } somewhere.
}
fclose(fp);
}
is probably where it belongs. Most likely
}
}
fclose(fp);
}
but you'll have to check your logic to make sure. After putting in a }
there before fclose(fp); so it'll compile...

fwrite(ingr,sizeof(struct ing),1,fp);
error C2664: 'fwrite' : cannot convert parameter 1 from 'ing' to 'const void
*'
ing? wtf is an ing? Looking up:
struct ing
{
int co,s,c;
}ingr;
Oh, so you want to pass the structure. So you need to take the address of
it.
fwrite(&ingr,sizeof(struct ing),1,fp);

ingr.sr-=m3;
error C2039: 'sr' : is not a member of 'ing'
Well, yeah, it's not. I see co, s and c. Maybe you meant s here, who
knows? Hopefully you do. Changing it to .s so it'll compile...

ingr.cr-=m3;
error C2039: 'cr' : is not a member of 'ing'
Hmm.. yeah, it's not either. I'll be a mind reader here and guess you meant
..c instead of .co and change it and go on....

fwrite(ingr,sizeof(struct ing),1,fp);
error C2664: 'fwrite' : cannot convert parameter 1 from 'ing' to 'const void
*'
Been here, done that. Changing it to
fwrite(&ingr,sizeof(struct ing),1,fp);

At very end of program:
}
error C2059: syntax error : '}'
Oh yeah, we put in that } up above. I guess you had your {'s and }'s
matching in number, just not in the right spots. So lets remove this.

Okay, go back, fix the print to printf, change void main to int main compile
and.. wtf?

'int main(void)' : overloaded function differs only by return type from
'void main(void)'
Sure enough, at the top of the program we have
void main();
why the heck would we need to prototype main. Lets remove this. This
leaves us with 4 warnings.

warning C4244: '=' : conversion from 'int' to 'char', possible loss of data
warning C4244: '=' : conversion from 'int' to 'char', possible loss of data
warning C4101: 'fp' : unreferenced local variable
warning C4244: '=' : conversion from 'int' to 'char', possible loss of data

The int's to chars I already explained with getche returning int and not
char. The fp you declared somewhere but didn't use.

What is rather horrible, however, is your last function.

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();
}
}

You have a function calling main, which is a no-no for many reasons. You
don't need a recursive program. receipt is called in 2 different places,
both inside of the function cash. Cash is called inside of main only if
they are paying cash (what, they can't continue ordering if they pay by
credit card?).

Move this "do you want to continue..." block up into main. before your
getch(); Put what you need repeated in main inside a while block. Such
as...

char Continue = 'y';
while ( Continue == 'y' || Continue == 'Y' }
{
// main code here

printf("\nDo you want to continue order coffee?y/n");
ch3=getche();
}

getch();



May 2 '07 #3
"Jim Langston" <ta*******@rocketmail.comwrote in message
news:fo*************@newsfe03.lga...
"i" <im*********@yahoo.co.inwrote in message
news:11**********************@h2g2000hsg.googlegro ups.com...
>#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[i].dc_n,&d[i].p,&d[i].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[i].cre,&ce[i].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[i].dc_n)&&(pin==d[i].p))
{
if(d[i].bal>j)
{
d[i].bal-=j;
fwrite(d,sizeof(struct debit),1,fp);
clear(n5,m5,ch_5);
receipt(n5,j);
}
else if(d[i].bal<0)
{
printf("\nBalance below zero");
}
else if(d[i].bal<j)
{
printf("\nThere is no enough money");
}
}
else
printf("\nIncorrect format");
}
else
if(ch_5=='w')
{
j=m5*10;
if((de==d[i].dc_n)&&(pin==d[i].p))
{
if(d[i].bal>j)
{
d[i].bal-=j;
fwrite(d,sizeof(d),1,fp);
clear(n5,m5,ch_5);
receipt(n5,j);
}
else if(d[i].bal<0)
{
printf("\nBalance below zero");
}
else if(d[i].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[i].cre==cd)
{
if(ce[i].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[i].cre==cd)
{
if(ce[i].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;

void main()
warning C4326: return type of 'main' should be 'int' instead of 'void'
Should be
int main()

ch=getche();
warning C4244: '=' : conversion from 'int' to 'char', possible loss of
data
Okay, that one is livable. I don't know why it returns an int when it
doesn't return an error code (no -1 or anything I can see). int ch; may
be better but *shrug*

print("\nEnter Mode of Payment\nFor Cash Enter 'c'\nFor debit card Enter
'd'\nFor Credit card Enter 'r'");
error C3861: 'print': identifier not found, even with argument-dependent
lookup
I'm sure you meant printf here.

ch1=getche();
warning C4244: '=' : conversion from 'int' to 'char', possible loss of
data
Same as before. Ignore, cast or int ch1.

void creditcard(int n2,int m2,char ch_2)
'creditcard' : local function definitions are illegal
Hmm, what? Oh, you're missing a } somewhere so it htinks you're still
inside a function, in this case the one that starts
void debit_card(int n5,int m5,char ch_5)
{
so debit_card is missing a ending } somewhere.
}
fclose(fp);
}
is probably where it belongs. Most likely
}
}
fclose(fp);
}
but you'll have to check your logic to make sure. After putting in a }
there before fclose(fp); so it'll compile...

fwrite(ingr,sizeof(struct ing),1,fp);
error C2664: 'fwrite' : cannot convert parameter 1 from 'ing' to 'const
void *'
ing? wtf is an ing? Looking up:
struct ing
{
int co,s,c;
}ingr;
Oh, so you want to pass the structure. So you need to take the address of
it.
fwrite(&ingr,sizeof(struct ing),1,fp);

ingr.sr-=m3;
error C2039: 'sr' : is not a member of 'ing'
Well, yeah, it's not. I see co, s and c. Maybe you meant s here, who
knows? Hopefully you do. Changing it to .s so it'll compile...

ingr.cr-=m3;
error C2039: 'cr' : is not a member of 'ing'
Hmm.. yeah, it's not either. I'll be a mind reader here and guess you
meant .c instead of .co and change it and go on....

fwrite(ingr,sizeof(struct ing),1,fp);
error C2664: 'fwrite' : cannot convert parameter 1 from 'ing' to 'const
void *'
Been here, done that. Changing it to
fwrite(&ingr,sizeof(struct ing),1,fp);

At very end of program:
}
error C2059: syntax error : '}'
Oh yeah, we put in that } up above. I guess you had your {'s and }'s
matching in number, just not in the right spots. So lets remove this.

Okay, go back, fix the print to printf, change void main to int main
compile and.. wtf?

'int main(void)' : overloaded function differs only by return type from
'void main(void)'
Sure enough, at the top of the program we have
void main();
why the heck would we need to prototype main. Lets remove this. This
leaves us with 4 warnings.

warning C4244: '=' : conversion from 'int' to 'char', possible loss of
data
warning C4244: '=' : conversion from 'int' to 'char', possible loss of
data
warning C4101: 'fp' : unreferenced local variable
warning C4244: '=' : conversion from 'int' to 'char', possible loss of
data

The int's to chars I already explained with getche returning int and not
char. The fp you declared somewhere but didn't use.

What is rather horrible, however, is your last function.

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();
}
}

You have a function calling main, which is a no-no for many reasons. You
don't need a recursive program. receipt is called in 2 different places,
both inside of the function cash. Cash is called inside of main only if
they are paying cash (what, they can't continue ordering if they pay by
credit card?).

Move this "do you want to continue..." block up into main. before your
getch(); Put what you need repeated in main inside a while block. Such
as...

char Continue = 'y';
while ( Continue == 'y' || Continue == 'Y' }
{
// main code here

printf("\nDo you want to continue order coffee?y/n");
ch3=getche();
}

getch();
My bad. I meant
Continue = getche();

Incidently, I really didn't look too much at the logic of your program at
all, just the syntax and obvious errors. A few may suggest using std::cin
instead of windows specific getch and getche() but it'll work with either.
May 2 '07 #4
i
On May 2, 1:08 pm, David Harmon <sou...@netcom.comwrote:
On 1 May 2007 23:03:51 -0700 in comp.lang.c++, i
<imhskala...@yahoo.co.inwrote,
Errors are:
1.Declaration is not allowed here

Where?
#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[i].dc_n,&d[i].p,&d[i].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[i].cre,&ce[i].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[i].dc_n)&&(pin==d[i].p))
{
if(d[i].bal>j)
{
d[i].bal-=j;
fwrite(d,sizeof(struct debit),1,fp);
clear(n5,m5,ch_5);
receipt(n5,j);
}
else if(d[i].bal<0)
{
printf("\nBalance below zero");
}
else if(d[i].bal<j)
{
printf("\nThere is no enough money");
}
}
else
printf("\nIncorrect format");
}
else
if(ch_5=='w')
{
j=m5*10;
if((de==d[i].dc_n)&&(pin==d[i].p))
{
if(d[i].bal>j)
{
d[i].bal-=j;
fwrite(d,sizeof(d),1,fp);
clear(n5,m5,ch_5);
receipt(n5,j);
}
else if(d[i].bal<0)
{
printf("\nBalance below zero");
}
else if(d[i].bal<j)
{
printf("\nThere is no enough money");
}
}
else
printf("\nIncorrect format");
}
fclose(fp);
}
1.void creditcard(int n2,int m2,char ch_2)
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[i].cre==cd)
{
if(ce[i].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[i].cre==cd)
{
if(ce[i].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();
}
}
3.}
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;

I marked 1,2,3 for errors

May 2 '07 #5
i wrote:
On May 2, 1:08 pm, David Harmon <sou...@netcom.comwrote:
>On 1 May 2007 23:03:51 -0700 in comp.lang.c++, i
<imhskala...@yahoo.co.inwrote,
>>Errors are:
1.Declaration is not allowed here

Where?
[...]
I believe a curly brace is missing here. Add it and see if it
fixes your problems.
1.void creditcard(int n2,int m2,char ch_2)
2.{

FILE *fp;
int i,j,cd;
[...]
if(ch3=='y')
{
main();
Also, you're not allowed to call 'main'. Just keep it in mind if
you want to learn proper C++.
}
}
3.}
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;

I marked 1,2,3 for errors
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
May 2 '07 #6
Your code appears to be C, not C++. Followups redirected to comp.lang.c

To c.l.c'ers -- sorry about the top-post, but given the length of the
embedded code, I figured it was justified in this rare case.
i wrote:
#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[i].dc_n,&d[i].p,&d[i].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[i].cre,&ce[i].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[i].dc_n)&&(pin==d[i].p))
{
if(d[i].bal>j)
{
d[i].bal-=j;
fwrite(d,sizeof(struct debit),1,fp);
clear(n5,m5,ch_5);
receipt(n5,j);
}
else if(d[i].bal<0)
{
printf("\nBalance below zero");
}
else if(d[i].bal<j)
{
printf("\nThere is no enough money");
}
}
else
printf("\nIncorrect format");
}
else
if(ch_5=='w')
{
j=m5*10;
if((de==d[i].dc_n)&&(pin==d[i].p))
{
if(d[i].bal>j)
{
d[i].bal-=j;
fwrite(d,sizeof(d),1,fp);
clear(n5,m5,ch_5);
receipt(n5,j);
}
else if(d[i].bal<0)
{
printf("\nBalance below zero");
}
else if(d[i].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[i].cre==cd)
{
if(ce[i].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[i].cre==cd)
{
if(ce[i].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;
May 2 '07 #7
Jim Langston wrote:
"i" <im*********@yahoo.co.inwrote in message
news:11**********************@h2g2000hsg.googlegro ups.com...
ch=getche();
warning C4244: '=' : conversion from 'int' to 'char', possible loss
of data Okay, that one is livable. I don't know why it returns an
int when it doesn't return an error code (no -1 or anything I can
see). int ch; may be better but shrug
Presumably (it's a non-standard function) it is similar to getchar() or
other similar ones. That means it can return EOF, which is a negative
integer.
You have a function calling main, which is a no-no for many reasons.
The principle one being that it's illegal in C++.

Brian
May 2 '07 #8
red floyd wrote:
Your code appears to be C, not C++. Followups redirected to
comp.lang.c
No, it's not C. Don't send garbage here.


Brian
May 2 '07 #9
"Default User" <de***********@yahoo.comwrote in message
news:59*************@mid.individual.net...
Jim Langston wrote:
>"i" <im*********@yahoo.co.inwrote in message
news:11**********************@h2g2000hsg.googlegr oups.com...
>ch=getche();
warning C4244: '=' : conversion from 'int' to 'char', possible loss
of data Okay, that one is livable. I don't know why it returns an
int when it doesn't return an error code (no -1 or anything I can
see). int ch; may be better but shrug

Presumably (it's a non-standard function) it is similar to getchar() or
other similar ones. That means it can return EOF, which is a negative
integer.
Yes, since this was a windows program, and since I use MS VC++ .net 2003 I
actually read the MSDN page on the call. Nothing in the documentation on
the call suggests it could return anything other than a character.

One thing I didn't think of, though, is for DBCS (Double Byte Character
Sets) where one character may not necessarily fit in one byte. So, if this
code is using getche instead of getch, then it is being designed for
multilingual, so this is actually an error, trying to fit a wide character
into a single byte won't fit.
>You have a function calling main, which is a no-no for many reasons.

The principle one being that it's illegal in C++.

May 6 '07 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by MrMike | last post: by
8 posts views Thread by JA | last post: by
12 posts views Thread by Bob Stearns | last post: by
reply views Thread by Miranda Evans | last post: by
23 posts views Thread by Prasad | last post: by
2 posts views Thread by Axel Gallus | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.