[Error] expected declaration or statement at end of input

This is a discussion on [Error] expected declaration or statement at end of input within the C Programming forums, part of the General Programming Boards category; Code: void statistics (void) { int i,success=0; float stat=0; for (i=0;i<150;i++) { if (AM[i].final_grade>=5) success+=1; } stat=(success/150)*100; printf ("The overall ...

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    5

    [Error] expected declaration or statement at end of input

    Code:
    void statistics (void)
    {
        int i,success=0;
        float stat=0;
        for (i=0;i<150;i++)
        {
            if (AM[i].final_grade>=5)
            success+=1;
        }
        stat=(success/150)*100;
        printf ("The overall number of students examined is 150, %f % were successful, which means that %d students were successful\n",stat,success);
    main;
    }
    [Error] expected declaration or statement at end of input
    This problem occurs when I try to run that part of the program.
    What should I do??

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    What is line 12 supposed to do?

    My thought is you should just delete line 12.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    5
    I tried to, but it didn't work..
    Any other suggestions?

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    You mean without seeing the rest of the code, or the rest of the error messages - nope, no idea at all.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Feb 2013
    Posts
    5
    this is the only error.
    Do you want to see the whole code?

  6. #6
    Registered User
    Join Date
    Feb 2013
    Posts
    5
    Quote Originally Posted by Kostas Kolivas View Post
    this is the only error.
    Do you want to see the whole code?
    and why?

  7. #7
    Registered User
    Join Date
    Jun 2005
    Posts
    6,208
    Quote Originally Posted by Kostas Kolivas View Post
    [Error] expected declaration or statement at end of input
    This problem occurs when I try to run that part of the program.
    What should I do??
    Your description is hideously unclear, but suggests you are successfully compiling, linking, and running the program. Presumably, therefore, the error message is produced by some function within the program, probably one that is calling the statistics() function. Accordingly, you need to examine the source code for the function that produces the error message.

    If you are going to post here, don't assume we have any information about YOUR problem unless you provide it.

    Forum members are rarely mindreaders so, unless you give useful information, you cannot expect useful advice.
    Right 98% of the time, and don't care about the other 3%.

  8. #8
    Registered User
    Join Date
    Nov 2012
    Posts
    1,053
    Read through your file first and make sure you aren't missing any parentheses or braces. This kind of error can occur because you forgot to close something, for example, and the compiler just keeps going until it hits the end of the file. It typically won't tell you where you "messed up" in this case, but the point of the problem is always above the first line number reported.

  9. #9
    Registered User
    Join Date
    Feb 2013
    Posts
    5
    I had forgotten to close the braces in Main. I wasn't worried about posting the code I just didn't see the necessity for it since this was the only problem. Clearly I was wrong. Thank you very much for your help. As you can already tell -I suppose - I am a newbie in programming and that's why I thought errors are function specific.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error: expected declaration or statement at end of input
    By ebyrne288 in forum C Programming
    Replies: 2
    Last Post: 11-15-2011, 04:31 PM
  2. Replies: 3
    Last Post: 04-28-2011, 11:27 PM
  3. Replies: 1
    Last Post: 03-02-2011, 07:07 PM
  4. expected declaration or statement at end of input
    By irelandmc in forum C Programming
    Replies: 5
    Last Post: 06-23-2009, 02:41 AM
  5. Replies: 13
    Last Post: 09-22-2007, 12:07 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21