Re: error correcting

Discussion in 'C Programming' started by red floyd, May 2, 2007.

  1. red floyd

    red floyd Guest

    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.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[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;
    > [/i][/i]
    [i][/i]
     
    red floyd, May 2, 2007
    #1
    1. Advertising

  2. In article <xB4_h.20692$>,
    red floyd <> wrote:
    >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>


    conio.h is not part of standard C, and has system-specific
    functionality.

    >> #include<process.h>


    As far as I know, process.h is not part of C99. It isn't part of C89,
    I'm sure.

    >> #include<string.h>
    >> char ch;
    >> int n,m;
    >> void main();


    main() is never void in C.

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


    I believe that might be the source of the problem. If I recall correctly,
    there is an existing clear() routine in "conio.h".
    --
    Prototypes are supertypes of their clones. -- maplesoft
     
    Walter Roberson, May 2, 2007
    #2
    1. Advertising

  3. red floyd

    Eric Sosman Guest

    red floyd wrote On 05/02/07 14:18,:
    > 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:
    > [... 351 lines of code ...]
    >
    >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;


    Three errors? That's nothing! I got fifteen:

    "foo.c", line 2: cannot find include file: <conio.h>
    "foo.c", line 3: cannot find include file: <process.h>
    "foo.c", line 261: syntax error before or at: void
    "foo.c", line 269: undefined symbol: cd
    "foo.c", line 274: undefined symbol: n2
    "foo.c", line 279: undefined symbol: m2
    "foo.c", line 279: undefined symbol: ch_2
    "foo.c", line 291: undefined symbol: m2
    "foo.c", line 296: undefined symbol: n2
    "foo.c", line 296: undefined symbol: ch_2
    "foo.c", line 321: argument #1 is incompatible with prototype:
    prototype: pointer to const void : "/usr/include/iso/stdio_iso.h", line 207
    argument : struct ing {int co, int s, int c}
    "foo.c", line 330: undefined struct/union member: sr
    "foo.c", line 331: undefined struct/union member: cr
    "foo.c", line 332: argument #1 is incompatible with prototype:
    prototype: pointer to const void : "/usr/include/iso/stdio_iso.h", line 207
    argument : struct ing {int co, int s, int c}
    "foo.c", line 351: syntax error before or at: }

    What do I win?

    Here's a suggestion: Next time you seek help for a
    mysterious problem, begin by trimming the code down to
    the smallest -- but still complete! -- fragment that
    demonstrates the trouble. (A benefit is that in the
    trimming-down process you will quite often discover what
    was wrong and be able to fix it immediately instead of
    waiting for disrespectful replies.) Then post that
    exact trimmed-down fragment, *and* post the exact error
    messages or the exact output or whatever it is that's
    baffling you. Posting 351 mostly irrelevant lines along
    with three errors and no indication of which lines they
    apply to is not a recipe for success.

    If you want effective answers, you must learn to ask
    effective questions.

    --
     
    Eric Sosman, May 2, 2007
    #3
  4. Walter Roberson said:

    >>> void clear(int,int,char);

    >
    > I believe that might be the source of the problem. If I recall
    > correctly, there is an existing clear() routine in "conio.h".


    Since it's not a standard header, it can contain anything, everything,
    and nothing. Borland's conio.h bears very little resemblance to
    Microsoft's.

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at the above domain, - www.
     
    Richard Heathfield, May 2, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wilq
    Replies:
    0
    Views:
    1,399
  2. MCP
    Replies:
    11
    Views:
    1,107
    Andrew Thompson
    Jun 11, 2004
  3. Sheldon
    Replies:
    13
    Views:
    602
    Scott David Daniels
    Oct 5, 2006
  4. zotkara

    Newbie needs help correcting code

    zotkara, Jan 3, 2006, in forum: C Programming
    Replies:
    25
    Views:
    705
    Randy Howard
    Jan 3, 2006
  5. i

    error correcting

    i, May 2, 2007, in forum: C++
    Replies:
    9
    Views:
    393
    Jim Langston
    May 6, 2007
Loading...

Share This Page