I'm having trouble with my code compiling, "error: return type defaults to 'int'"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kfindley
    New Member
    • Feb 2010
    • 6

    I'm having trouble with my code compiling, "error: return type defaults to 'int'"

    #include <stdio.h>
    main() /*program which introduces keyboard input */
    {
    int number;

    printf ("Type in a number \n");
    scanf ("%d", &number);
    printf ("The number you typed was %d\n", number);
    }


    I then try to compile with "gcc -Wall -Werror -Lm user_input.c"
    but I am receiving an error. Any suggestions on how to fix my code?
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    You need a return type int on main():

    Code:
    int main()
    {
        
    }
    Not specifying a return type defaults to int in C but not in C++. Try that.

    Comment

    • kfindley
      New Member
      • Feb 2010
      • 6

      #3
      This worked perfectly!
      Thank you!

      Comment

      Working...