473,546 Members | 2,244 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

error correcting

i
#include<stdio. h>
#include<conio. h>
#include<proces s.h>
#include<string .h>
char ch;
int n,m;
void main();
char check(int,int,c har);
void cash(int,int,ch ar);
void debit_card(int, int,char);
void creditcard(int no,int mo,char cho);
void clear(int,int,c har);
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("ingre dient.dat","w") ;
scanf("%d%d%d", &ingr.co,&ingr. s,&ingr.c);
fwrite(fp,sizeo f(struct ing),1,fp);
fclose(fp);
fp=fopen("debit Card.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("credi tCard.dat","w") ;
for(i=0;i<10;i+ +)
scanf("%d%f",&c e[i].cre,&ce[i].cl);
fwrite(ce,sizeo f(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,c h);
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("ingre dient.dat","r+t ");
fread(&ingr,siz eof(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>=m 6))
{
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==5 00)&&(k==1000))
{
printf("\nInval id Cash.Give only 1,2 and 5 rupee coins");
scanf("%d",&k);
}
if((l==10)&&(l= =20)&&(l==50)&& (l==100)&&(l==5 00)&&(l==1000))
{
printf("\nInval id Cash.Give only 1,2 and 5 rupee coins");
scanf("%d",&l);
}
if((o==10)&&(o= =20)&&(o==50)&& (o==100)&&(o==5 00)&&(o==1000))
{
printf("\nInval id 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==5 00)&&(k==1000))
{
printf("\nInval id Cash.Give only 1,2 and 5 rupee coins");
scanf("%d",&k);
}
if((l==10)&&(l= =20)&&(l==50)&& (l==100)&&(l==5 00)&&(l==1000))
{
printf("\nInval id Cash.Give only 1,2 and 5 rupee coins");
scanf("%d",&l);
}
if((o==10)&&(o= =20)&&(o==50)&& (o==100)&&(o==5 00)&&(o==1000))
{
printf("\nInval id 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("debit Card.dat","r+t" );
fread(&d[10],sizeof(struct debit),10,fp);
printf("\nEnter debit card number and pin number");
scanf("%d%d",&d e,&pin);
for(i=0;i<sizeo f(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("\nBalan ce below zero");
}
else if(d[i].bal<j)
{
printf("\nThere is no enough money");
}
}
else
printf("\nIncor rect 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("\nBalan ce below zero");
}
else if(d[i].bal<j)
{
printf("\nThere is no enough money");
}
}
else
printf("\nIncor rect format");
}
fclose(fp);
}
void creditcard(int n2,int m2,char ch_2)
{

FILE *fp;
int i,j,cd;
fp=fopen("credi tCard.dat","r+t ");
fread(&ce[10],sizeof(struct credit),10,fp);
printf("\nEnter the credit card number");
scanf("%d",&cd) ;
for(i=0;i<sizeo f(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("\nIncor rect 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("\nIncor rect format");
}
}
}
fclose(fp);
}
void clear(int n3,int m3,char ch_3)
{
FILE *fp;

fp=fopen("ingre dient.dat","r+t ");
if(ch_3=='b')
{
fread(&ingr,siz eof(struct ing),1,fp);
ingr.co-=n3;
fwrite(ingr,siz eof(struct ing),1,fp);
printf("\nCoffe e served");
fclose(fp);
}
else
if(ch_3=='w')
{
fread(&ingr,siz eof(struct ing),1,fp);
ingr.co-=m3;
ingr.sr-=m3;
ingr.cr-=m3;
fwrite(ingr,siz eof(struct ing),1,fp);
printf("\nCoffe e 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
9 2935
On 1 May 2007 23:03:51 -0700 in comp.lang.c++, i
<im*********@ya hoo.co.inwrote,
>Errors are:
1.Declaratio n is not allowed here
Where?

May 2 '07 #2
"i" <im*********@ya hoo.co.inwrote in message
news:11******** **************@ h2g2000hsg.goog legroups.com...
#include<stdio. h>
#include<conio. h>
#include<proces s.h>
#include<string .h>
char ch;
int n,m;
void main();
char check(int,int,c har);
void cash(int,int,ch ar);
void debit_card(int, int,char);
void creditcard(int no,int mo,char cho);
void clear(int,int,c har);
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("ingre dient.dat","w") ;
scanf("%d%d%d", &ingr.co,&ingr. s,&ingr.c);
fwrite(fp,sizeo f(struct ing),1,fp);
fclose(fp);
fp=fopen("debit Card.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("credi tCard.dat","w") ;
for(i=0;i<10;i+ +)
scanf("%d%f",&c e[i].cre,&ce[i].cl);
fwrite(ce,sizeo f(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,c h);
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("ingre dient.dat","r+t ");
fread(&ingr,siz eof(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>=m 6))
{
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==5 00)&&(k==1000))
{
printf("\nInval id Cash.Give only 1,2 and 5 rupee coins");
scanf("%d",&k);
}
if((l==10)&&(l= =20)&&(l==50)&& (l==100)&&(l==5 00)&&(l==1000))
{
printf("\nInval id Cash.Give only 1,2 and 5 rupee coins");
scanf("%d",&l);
}
if((o==10)&&(o= =20)&&(o==50)&& (o==100)&&(o==5 00)&&(o==1000))
{
printf("\nInval id 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==5 00)&&(k==1000))
{
printf("\nInval id Cash.Give only 1,2 and 5 rupee coins");
scanf("%d",&k);
}
if((l==10)&&(l= =20)&&(l==50)&& (l==100)&&(l==5 00)&&(l==1000))
{
printf("\nInval id Cash.Give only 1,2 and 5 rupee coins");
scanf("%d",&l);
}
if((o==10)&&(o= =20)&&(o==50)&& (o==100)&&(o==5 00)&&(o==1000))
{
printf("\nInval id 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("debit Card.dat","r+t" );
fread(&d[10],sizeof(struct debit),10,fp);
printf("\nEnter debit card number and pin number");
scanf("%d%d",&d e,&pin);
for(i=0;i<sizeo f(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("\nBalan ce below zero");
}
else if(d[i].bal<j)
{
printf("\nThere is no enough money");
}
}
else
printf("\nIncor rect 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("\nBalan ce below zero");
}
else if(d[i].bal<j)
{
printf("\nThere is no enough money");
}
}
else
printf("\nIncor rect format");
}
fclose(fp);
}
void creditcard(int n2,int m2,char ch_2)
{

FILE *fp;
int i,j,cd;
fp=fopen("credi tCard.dat","r+t ");
fread(&ce[10],sizeof(struct credit),10,fp);
printf("\nEnter the credit card number");
scanf("%d",&cd) ;
for(i=0;i<sizeo f(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("\nIncor rect 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("\nIncor rect format");
}
}
}
fclose(fp);
}
void clear(int n3,int m3,char ch_3)
{
FILE *fp;

fp=fopen("ingre dient.dat","r+t ");
if(ch_3=='b')
{
fread(&ingr,siz eof(struct ing),1,fp);
ingr.co-=n3;
fwrite(ingr,siz eof(struct ing),1,fp);
printf("\nCoffe e served");
fclose(fp);
}
else
if(ch_3=='w')
{
fread(&ingr,siz eof(struct ing),1,fp);
ingr.co-=m3;
ingr.sr-=m3;
ingr.cr-=m3;
fwrite(ingr,siz eof(struct ing),1,fp);
printf("\nCoffe e 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,siz eof(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,si zeof(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,siz eof(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,si zeof(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*******@rock etmail.comwrote in message
news:fo******** *****@newsfe03. lga...
"i" <im*********@ya hoo.co.inwrote in message
news:11******** **************@ h2g2000hsg.goog legroups.com...
>#include<stdio .h>
#include<conio .h>
#include<proce ss.h>
#include<strin g.h>
char ch;
int n,m;
void main();
char check(int,int,c har);
void cash(int,int,ch ar);
void debit_card(int, int,char);
void creditcard(int no,int mo,char cho);
void clear(int,int,c har);
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("\nFo r Black Coffee\t\t Enter 'b'\nFor White Coffee\t\t Enter
'w'");
if(j==1)
{
fp=fopen("ingr edient.dat","w" );
scanf("%d%d%d", &ingr.co,&ingr. s,&ingr.c);
fwrite(fp,size of(struct ing),1,fp);
fclose(fp);
fp=fopen("debi tCard.dat","w") ;
for(i=0;i<10;i ++)
scanf("%d%d%f", &d[i].dc_n,&d[i].p,&d[i].bal);
fwrite(d,sizeo f(struct ing),10,fp);
fclose(fp);
fp=fopen("cred itCard.dat","w" );
for(i=0;i<10;i ++)
scanf("%d%f",&c e[i].cre,&ce[i].cl);
fwrite(ce,size of(struct credit),10,fp);
fclose(fp);
j++;
}
printf("\nFo r 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("ingr edient.dat","r+ t");
fread(&ingr,si zeof(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>=m 6))
{
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==5 00)&&(k==1000))
{
printf("\nInval id Cash.Give only 1,2 and 5 rupee coins");
scanf("%d",&k);
}
if((l==10)&&(l= =20)&&(l==50)&& (l==100)&&(l==5 00)&&(l==1000))
{
printf("\nInval id Cash.Give only 1,2 and 5 rupee coins");
scanf("%d",&l);
}
if((o==10)&&(o= =20)&&(o==50)&& (o==100)&&(o==5 00)&&(o==1000))
{
printf("\nInval id 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==5 00)&&(k==1000))
{
printf("\nInval id Cash.Give only 1,2 and 5 rupee coins");
scanf("%d",&k);
}
if((l==10)&&(l= =20)&&(l==50)&& (l==100)&&(l==5 00)&&(l==1000))
{
printf("\nInval id Cash.Give only 1,2 and 5 rupee coins");
scanf("%d",&l);
}
if((o==10)&&(o= =20)&&(o==50)&& (o==100)&&(o==5 00)&&(o==1000))
{
printf("\nInval id 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("debit Card.dat","r+t" );
fread(&d[10],sizeof(struct debit),10,fp);
printf("\nEnter debit card number and pin number");
scanf("%d%d",&d e,&pin);
for(i=0;i<sizeo f(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("\nBalan ce below zero");
}
else if(d[i].bal<j)
{
printf("\nThere is no enough money");
}
}
else
printf("\nIncor rect 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("\nBalan ce below zero");
}
else if(d[i].bal<j)
{
printf("\nThere is no enough money");
}
}
else
printf("\nIncor rect format");
}
fclose(fp);
}
void creditcard(int n2,int m2,char ch_2)
{

FILE *fp;
int i,j,cd;
fp=fopen("cred itCard.dat","r+ t");
fread(&ce[10],sizeof(struct credit),10,fp);
printf("\nEnte r the credit card number");
scanf("%d",&cd );
for(i=0;i<size of(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("\nIncor rect 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("\nIncor rect format");
}
}
}
fclose(fp);
}
void clear(int n3,int m3,char ch_3)
{
FILE *fp;

fp=fopen("ingr edient.dat","r+ t");
if(ch_3=='b' )
{
fread(&ingr,siz eof(struct ing),1,fp);
ingr.co-=n3;
fwrite(ingr,siz eof(struct ing),1,fp);
printf("\nCoffe e served");
fclose(fp);
}
else
if(ch_3=='w')
{
fread(&ingr,siz eof(struct ing),1,fp);
ingr.co-=m3;
ingr.sr-=m3;
ingr.cr-=m3;
fwrite(ingr,siz eof(struct ing),1,fp);
printf("\nCoffe e served");
fclose(fp);
}
}
void receipt(int n4,int j1)
{
char ch3;

printf("\n**** *************** *********RECEIP T************** *************** *****");
printf("\nTh e Number of Coffees %d",n4);
printf("\nTota l 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.Declaratio n 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,siz eof(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,si zeof(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,siz eof(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,si zeof(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...@ya hoo.co.inwrote,
Errors are:
1.Declaration is not allowed here

Where?
#include<stdio. h>
#include<conio. h>
#include<proces s.h>
#include<string .h>
char ch;
int n,m;
void main();
char check(int,int,c har);
void cash(int,int,ch ar);
void debit_card(int, int,char);
void creditcard(int no,int mo,char cho);
void clear(int,int,c har);
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("ingre dient.dat","w") ;
scanf("%d%d%d", &ingr.co,&ingr. s,&ingr.c);
fwrite(fp,sizeo f(struct ing),1,fp);
fclose(fp);
fp=fopen("debit Card.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("credi tCard.dat","w") ;
for(i=0;i<10;i+ +)
scanf("%d%f",&c e[i].cre,&ce[i].cl);
fwrite(ce,sizeo f(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,c h);
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("ingre dient.dat","r+t ");
fread(&ingr,siz eof(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>=m 6))
{
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==5 00)&&(k==1000))
{
printf("\nInval id Cash.Give only 1,2 and 5 rupee coins");
scanf("%d",&k);
}
if((l==10)&&(l= =20)&&(l==50)&& (l==100)&&(l==5 00)&&(l==1000))
{
printf("\nInval id Cash.Give only 1,2 and 5 rupee coins");
scanf("%d",&l);
}
if((o==10)&&(o= =20)&&(o==50)&& (o==100)&&(o==5 00)&&(o==1000))
{
printf("\nInval id 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==5 00)&&(k==1000))
{
printf("\nInval id Cash.Give only 1,2 and 5 rupee coins");
scanf("%d",&k);
}
if((l==10)&&(l= =20)&&(l==50)&& (l==100)&&(l==5 00)&&(l==1000))
{
printf("\nInval id Cash.Give only 1,2 and 5 rupee coins");
scanf("%d",&l);
}
if((o==10)&&(o= =20)&&(o==50)&& (o==100)&&(o==5 00)&&(o==1000))
{
printf("\nInval id 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("debit Card.dat","r+t" );
fread(&d[10],sizeof(struct debit),10,fp);
printf("\nEnter debit card number and pin number");
scanf("%d%d",&d e,&pin);
for(i=0;i<sizeo f(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("\nBalan ce below zero");
}
else if(d[i].bal<j)
{
printf("\nThere is no enough money");
}
}
else
printf("\nIncor rect 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("\nBalan ce below zero");
}
else if(d[i].bal<j)
{
printf("\nThere is no enough money");
}
}
else
printf("\nIncor rect format");
}
fclose(fp);
}
1.void creditcard(int n2,int m2,char ch_2)
2.{

FILE *fp;
int i,j,cd;
fp=fopen("credi tCard.dat","r+t ");
fread(&ce[10],sizeof(struct credit),10,fp);
printf("\nEnter the credit card number");
scanf("%d",&cd) ;
for(i=0;i<sizeo f(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("\nIncor rect 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("\nIncor rect format");
}
}
}
fclose(fp);
}
void clear(int n3,int m3,char ch_3)
{
FILE *fp;

fp=fopen("ingre dient.dat","r+t ");
if(ch_3=='b')
{
fread(&ingr,siz eof(struct ing),1,fp);
ingr.co-=n3;
fwrite(ingr,siz eof(struct ing),1,fp);
printf("\nCoffe e served");
fclose(fp);
}
else
if(ch_3=='w')
{
fread(&ingr,siz eof(struct ing),1,fp);
ingr.co-=m3;
ingr.sr-=m3;
ingr.cr-=m3;
fwrite(ingr,siz eof(struct ing),1,fp);
printf("\nCoffe e 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...@y ahoo.co.inwrote ,
>>Errors are:
1.Declarati on 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<proces s.h>
#include<string .h>
char ch;
int n,m;
void main();
char check(int,int,c har);
void cash(int,int,ch ar);
void debit_card(int, int,char);
void creditcard(int no,int mo,char cho);
void clear(int,int,c har);
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("ingre dient.dat","w") ;
scanf("%d%d%d", &ingr.co,&ingr. s,&ingr.c);
fwrite(fp,sizeo f(struct ing),1,fp);
fclose(fp);
fp=fopen("debit Card.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("credi tCard.dat","w") ;
for(i=0;i<10;i+ +)
scanf("%d%f",&c e[i].cre,&ce[i].cl);
fwrite(ce,sizeo f(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,c h);
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("ingre dient.dat","r+t ");
fread(&ingr,siz eof(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>=m 6))
{
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==5 00)&&(k==1000))
{
printf("\nInval id Cash.Give only 1,2 and 5 rupee coins");
scanf("%d",&k);
}
if((l==10)&&(l= =20)&&(l==50)&& (l==100)&&(l==5 00)&&(l==1000))
{
printf("\nInval id Cash.Give only 1,2 and 5 rupee coins");
scanf("%d",&l);
}
if((o==10)&&(o= =20)&&(o==50)&& (o==100)&&(o==5 00)&&(o==1000))
{
printf("\nInval id 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==5 00)&&(k==1000))
{
printf("\nInval id Cash.Give only 1,2 and 5 rupee coins");
scanf("%d",&k);
}
if((l==10)&&(l= =20)&&(l==50)&& (l==100)&&(l==5 00)&&(l==1000))
{
printf("\nInval id Cash.Give only 1,2 and 5 rupee coins");
scanf("%d",&l);
}
if((o==10)&&(o= =20)&&(o==50)&& (o==100)&&(o==5 00)&&(o==1000))
{
printf("\nInval id 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("debit Card.dat","r+t" );
fread(&d[10],sizeof(struct debit),10,fp);
printf("\nEnter debit card number and pin number");
scanf("%d%d",&d e,&pin);
for(i=0;i<sizeo f(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("\nBalan ce below zero");
}
else if(d[i].bal<j)
{
printf("\nThere is no enough money");
}
}
else
printf("\nIncor rect 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("\nBalan ce below zero");
}
else if(d[i].bal<j)
{
printf("\nThere is no enough money");
}
}
else
printf("\nIncor rect format");
}
fclose(fp);
}
void creditcard(int n2,int m2,char ch_2)
{

FILE *fp;
int i,j,cd;
fp=fopen("credi tCard.dat","r+t ");
fread(&ce[10],sizeof(struct credit),10,fp);
printf("\nEnter the credit card number");
scanf("%d",&cd) ;
for(i=0;i<sizeo f(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("\nIncor rect 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("\nIncor rect format");
}
}
}
fclose(fp);
}
void clear(int n3,int m3,char ch_3)
{
FILE *fp;

fp=fopen("ingre dient.dat","r+t ");
if(ch_3=='b')
{
fread(&ingr,siz eof(struct ing),1,fp);
ingr.co-=n3;
fwrite(ingr,siz eof(struct ing),1,fp);
printf("\nCoffe e served");
fclose(fp);
}
else
if(ch_3=='w')
{
fread(&ingr,siz eof(struct ing),1,fp);
ingr.co-=m3;
ingr.sr-=m3;
ingr.cr-=m3;
fwrite(ingr,siz eof(struct ing),1,fp);
printf("\nCoffe e 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*********@ya hoo.co.inwrote in message
news:11******** **************@ h2g2000hsg.goog legroups.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.indiv idual.net...
Jim Langston wrote:
>"i" <im*********@ya hoo.co.inwrote in message
news:11******* *************** @h2g2000hsg.goo glegroups.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4098
by: MrMike | last post by:
The following snippet of code is part of a larger module, and the code shown here is giving me an error. The error is "The remote server returned an error: (401) Unauthorized." The error occurs on the line 'objResponse = objRequest.GetResponse() ........................................................................................ Private...
8
2958
by: JA | last post by:
Hi, I have this JavaScript that is supposed to show random products from my database, and show something different every time you refresh or revisit. But I keep getting an error - on my computer - that says Syntax Error in Line 2. There is no error on most other computers, and the products show, but another script on the page, an article...
12
4740
by: Bob Stearns | last post by:
I am trying to create a duplicate prevention trigger: CREATE TRIGGER is3.ard_u_unique BEFORE UPDATE OF act_recov_date ON is3.flushes REFERENCING NEW AS N FOR EACH ROW MODE DB2SQL WHEN (N.act_recov_date IS NOT NULL) BEGIN ATOMIC select count(*) into v_n from is3.flushes
0
3300
by: Miranda Evans | last post by:
I noticed several postings about issues related to "run-time error 3061", and I observed that the solutions to these issues appear to involve correcting something within the SQL code. I'm encountering the "run-time error 3061" issue, but I'm not sure how to go about correcting the SQL. My hunch is that I have not properly constructed things...
12
2395
by: craig | last post by:
Quick question for the experts... Whenever I set the Image property of a PictureBox on one of my windows forms to a PNG graphic file on my hard drive, I get the following runtime error when I try to run the app: Exception Type: System.Resources.MissingManifestResourceException Message: Could not find any resources appropriate for the...
23
412
by: Prasad | last post by:
Hi All, I am executing simple hello world program. But, getting compile time errors. What is the problem here? prasad@D-T11673A:~/programs/c> cat bst.cpp #include<iostream> using namespace std;
16
2594
by: lawrence k | last post by:
I've made it habit to check all returns in my code, and usually, on most projects, I'll have an error function that reports error messages to some central location. I recently worked on a project where someone suggested to me I was spending too much time writing error messages, and that I was therefore missing the benefit of using a scripting...
1
1689
by: srinivasarv | last post by:
Dear Friends, kindly help me in correcting the following code This code is for printing the report from the combo box after selection which connects to different reports as selected. I have written this code behind the combo box. Private Sub Bank_Name_AfterUpdate() Dim rpt As String
2
1957
by: Axel Gallus | last post by:
I am desperately looking for some resources dealing with error handling in c++. Don't get me wrong.... I have very detailed knowledge of exceptions, assertions and invariants, but what is missing it the following: 1.) When developing a commercial application, how does the usage of exceptions and assertions as well as
0
7507
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7435
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7947
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7461
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6030
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5080
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1922
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.