Missing function header

This is a discussion on Missing function header within the C++ Programming forums, part of the General Programming Boards category; So this whole C++ programming thing is new to me I'm working on this code for a class but i'm ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    3

    Question Missing function header

    So this whole C++ programming thing is new to me I'm working on this code for a class but i'm stuck and don't know how to fix it i'm using microsoft visual C++ 6.0 heres the error i get:
    error C2447: missing function header (old-style formal list?) and heres the code
    Code:
    #include <iostream>
    
    using namespace std;
    
    void main(void);
    {  int num1=34, int num2=112;
       float sum, float avg;
       cout << "+------------------------+" << endl;
       cout << "| My Name is Rashad Bell |" << endl;
       cout << "+------------------------+" << endl:
       cout << endl;
    
       cout << " num1 equals " << num1 << " num2 equals " << num2 << endl;
    
       sum = num1 + num2;
    
       cout << " sum equals " << sum << endl;
    
       avg = sum / 2;
    
       cout << " sum equals " << sum << endl;
    }
    help of course will be greatly appreciated because i'm really at a loss

  2. #2
    Registered User codingmaster's Avatar
    Join Date
    Sep 2002
    Posts
    309
    It should be:

    int main()
    {
    int num1=34, num2=112;
    float sum, avg;
    .
    .
    .
    .
    .

    return 0;
    }

    Don't use void main(void)
    U will be killed by a lot of angry programmers, cause void main(void) is not ANSI standard

    Please use: int main()
    and return 0;

    int main()
    {
    return 0;
    }

  3. #3
    Registered User codingmaster's Avatar
    Join Date
    Sep 2002
    Posts
    309
    U have more mistakes in the code, u have used sometimes the : instead of ; and u have written void main(void); it should be without ;

    So here the code:

    #include <iostream>

    using namespace std;

    int main()
    {
    int num1=34, num2=112;
    float sum, avg;
    cout << "+------------------------+" << endl;
    cout << "| My Name is Rashad Bell |" << endl;
    cout << "+------------------------+" << endl;
    cout << endl;

    cout << " num1 equals " << num1 << " num2 equals " << num2 << endl;

    sum = num1 + num2;

    cout << " sum equals " << sum << endl;

    avg = sum / 2;

    cout << " sum equals " << sum << endl;
    return 0;
    }


    Compiled on Microsoft Visual Studio C++ 6 Professional
    0 errors, 0 warnings

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    37
    yeha and abit of syntax errors too , let a beginner help a beginner, shall we?


    try this:

    Code:
    #include<iostream.h>
    
    int main()
    {  
       int num1=34;
       int num2=112;
       float sum,avg;
       cout << "+------------------------+" << endl;
       cout << "| My Name is Rashad Bell |" << endl;
       cout << "+------------------------+" << endl;
       cout << endl;
    
       cout << " num1 equals " << num1 << " num2 equals " << num2 << endl;
    
       sum = float (num1 + num2);
    
       cout << " sum equals " << sum << endl;
    
       avg = sum / 2;
    
       cout << " average equals " << avg << endl;
       return 0;
    }

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    37
    damn codingmaster beat me to it !

    0 errors 0 warnings really?

    I thought if you dont do abit of casting for this you will get a
    warning coz he declared the 2 numbers to be "int" the sum
    of them two is a "float"

    so it should be sum =float (num1 + num2); ?
    Last edited by mellisa; 01-21-2003 at 04:32 PM.

  6. #6
    Registered User codingmaster's Avatar
    Join Date
    Sep 2002
    Posts
    309
    hmm
    a bit faster.....

    grrr

    Forgotten some ; and :, so have to edit the code

    *grin*

  7. #7
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main(void)
    {
       int num1=34; int num2=112;
    
       cout << "+------------------------+" << endl;
       cout << "| My Name is Rashad Bell |" << endl;
       cout << "+------------------------+" << endl;
       cout << endl;
    
       cout << " num1 equals " << num1 << " num2 equals " << num2 << endl;
       cout << " sum equals " << num1 + num2 << endl;
       cout << " ave equals " << (num1 + num2) / 2.0 << endl;
    
       return 0;
    }
    Removed unneeded variables.
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

  8. #8
    Registered User
    Join Date
    Jan 2003
    Posts
    3
    just wanted to say thanks
    I appreciate the help and i'll probably be asking more questions and maybe one day i'll be as quick as you guys to answer them

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM

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