error in compiling addition program

This is a discussion on error in compiling addition program within the C Programming forums, part of the General Programming Boards category; hello, i'm total noob at c coding. My teacher gave me some codes to test (addition program) Code: #include <stdio.h> ...

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    33

    Question error in compiling addition program

    hello, i'm total noob at c coding. My teacher gave me some codes to test (addition program)
    Code:
    #include <stdio.h>
    #include <conio.h>
    main()
    {
    clrscr()
    int n1,n2,sum;
    printf("\nInput two numbers:");
    scanf("%d,%d",&n1,&n2);
    sum = n1+n2
    printf("\nThe sum is "%d",sum);
    getch();
    }
    when i compile the code
    i get an error
    Expression syntax in function main()
    undefined symbol 'n1' in function main()
    undefined symbol 'n2' in function main()
    undefined symbol 'sum' in function main()
    i don't know what to do with this n1, n2,sum or make them a defined symbol i guess. plss help

  2. #2
    Epy
    Epy is offline
    Fortran lover Epy's Avatar
    Join Date
    Sep 2009
    Location
    California, USA
    Posts
    949
    You're missing semicolons at the end of certain lines, and main() needs a type, namely int. As such, main() needs to return an int, 0 if successful.

  3. #3
    Registered User
    Join Date
    Dec 2011
    Posts
    33
    thanks epy about missing a semicolon at clrscr(). now i have only 1 error and that is
    line 10 : undefined symbol 'd' in function main ()
    line 10 : unterminated string or character constant in function main
    Code:
    printf("\n, The sum is "%d",sum);

  4. #4
    Registered User
    Join Date
    Dec 2011
    Posts
    33
    no need to reply
    i found the problem it was missing a "" in line 10.

  5. #5
    Epy
    Epy is offline
    Fortran lover Epy's Avatar
    Join Date
    Sep 2009
    Location
    California, USA
    Posts
    949
    Yeah, when using certain characters within a string in C, you need to "escape" them, i.e.

    Code:
    printf("\nThe sum is \"%d\"", sum);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 10-08-2010, 01:30 PM
  2. error compiling a little program
    By fbs777 in forum C Programming
    Replies: 4
    Last Post: 03-17-2009, 10:35 PM
  3. Linker error when compiling Qt program
    By shashidhara_01 in forum C Programming
    Replies: 2
    Last Post: 04-29-2008, 09:30 AM
  4. Replies: 7
    Last Post: 03-05-2008, 01:56 PM
  5. Internal Error while compiling Pro*C program..
    By anwar_pat in forum C Programming
    Replies: 2
    Last Post: 03-21-2006, 04:47 AM

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