declaration terminated incorrectly

This is a discussion on declaration terminated incorrectly within the C++ Programming forums, part of the General Programming Boards category; I'm learning c++ on my own and was looking for a little pro help. Thanx in advance. This is the ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    20

    declaration terminated incorrectly

    I'm learning c++ on my own and was looking for a little pro help. Thanx in advance.

    This is the error:

    Error E2040 c:\mprog\mif.cpp 10: Declaration terminated incorrectly in function
    main()
    Error E2040 c:\mprog\mif.cpp 11: Declaration terminated incorrectly in function
    main()
    Error E2121 c:\mprog\mif.cpp 12: Function call missing ) in function main()
    *** 3 errors in Compile ***

    This is the code:

    #include <iostream.h>

    int f_gather(void);
    int f_add(int data1, int data2);
    void f_show(int result);

    main()
    {
    int 1st_number=f_gather(void);//ln 10
    int 2nd_number=f_gather(void);//ln11
    int answer=f_add(1st_number, 2nd_number);//ln12
    f_show(answer);
    return (0);
    }

    int f_gather(void)
    {
    int answer;
    cout<<"enter number to be added"<<endl;
    cin>>answer;
    return (answer);
    }

    int f_add(int data1, int data2)
    {
    return (data1+data2);
    }

    void f_show(int result)
    {
    cout<<result;
    }

  2. #2
    In The Light
    Join Date
    Oct 2001
    Posts
    598

    try this

    howdy,
    i am also teaching myself.
    these are my observations:

    main should not be called with out a type -
    main() should be int main()

    lines 10 and 11 try leaving the braces empty it does not appear that you are trying to pass any values in these function calls also,when i tryed it in gcc i had to take the digit out of the variable names:

    int st_number;
    st_number = f_gather();//ln 10
    int nd_number;
    nd_number = f_gather();//ln 11

    seems to work fine after that.

    is there a restriction on using digits for the first char of a variable? it would appear so.

    thanks for the lesson >Clane<

    M.R.

  3. #3
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    Yes, you can't have variable begining with numbers in c++.
    also while calling of functions it's not needed to put void, empty brackets will do.

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    20
    yep, the diget made the difference. Thanx. What's this gcc i? Is it free?

  5. #5
    In The Light
    Join Date
    Oct 2001
    Posts
    598

    you has to ask

    howdy,

    >What's this gcc i? Is it free?<

    gcc is absolutely FREE FREE FREE
    *itld get control of himself*
    gcc is the compiler that runs in the linux enviroment it can be obtained in several places on the web as well as with most distro's of linux.
    the version i used is gcc 2.96 and compiled from in the emacs editor, both running in linux RedHat 7.2
    i cant directly remember any of the addresses to the GNU (another linux thing) sites that deal with gcc, maybe someone else can post some.

    thanks
    M.R.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  2. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 02:49 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  4. Errors with including winsock 2 lib
    By gamingdl'er in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2005, 07:13 PM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM

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