Help please: "Declaration not allowed here"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • armelle22
    New Member
    • Aug 2012
    • 4

    Help please: "Declaration not allowed here"

    Code:
    #includ<stdio.h>
    #include<conio.h>
    
    void main()
    {
    
    clrscr();
    int one, five, ten, res1, res_1, res_2, res_3;
    float two_fve, res_4, res2;
    
    printf("\n\t\tMoney Denomination!");
    printf("\n\nEnter number of coins per value");
    printf("\n\nP10 coin");
    scanf("%d",&ten);
    printf("\nP5 coin:");
    scanf("%d",&five);
    printf("\nP1 coin:");
    scanf("%d",&one);
    printf("\n25 centavo coin:");
    scanf("%f",&two_fve);
    
    res1=ten+five+one+two_fve;
    res_1=ten*10;
    res_2=five*5;
    res_3=one*1;
    res_4=two_fve*.25;
    res2=res_1+res_2+res_3+res_4;
    
    printf("You have a total of %d coins, amounting to Php. %f.");
    
    getch();
    }
    I don't get why I have such errors and when I was figuring it out, the "Declaratio n not allowed here" popped... I'm a newbie and I don't think I haven't develop much common sense....
  • whodgson
    Contributor
    • Jan 2007
    • 542

    #2
    "such errors" ......like what?
    btw main() has type int not void but this would not be your problem.

    Comment

    • armelle22
      New Member
      • Aug 2012
      • 4

      #3
      Such as... "Function call missing )" even thou ) is properly placed there.. "'res2 and res1 is assigned a value that is never used" even thou, as you can see, I used it...

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        It would help if you could post the full debugger text.

        But one glaring error is that your last printf function is incorrect. You never specify which variables to print out in place of the placeholders.

        Comment

        • weaknessforcats
          Recognized Expert Expert
          • Mar 2007
          • 9214

          #5
          And don't forget you cannot define variables after the function starts. That is, once you call clrscr()you may not more variables defined.

          Comment

          • Shubhangi24
            New Member
            • Oct 2012
            • 20

            #6
            In C programming your variable declaration should be exactly after at starting of your block(i.e after {(opening curly brace)). just alter the sequence :- put clrscr() after variable declaration.. It will run perfectly....

            Comment

            • sgayathri2412
              New Member
              • Oct 2012
              • 8

              #7
              //error begins with your header file inclusion.
              #includ<stdio.h >

              //printf statement is absolutely incorrect..you haven't //mentioned what variables should be assigned in the place of //format specifiers.
              printf("You have a total of %d coins, amounting to Php. %f.");

              //declare the variables and then use the function clrscr() orelse it w'd cause trouble to your coding

              Comment

              Working...