Error help PLEASE!!!!!

This is a discussion on Error help PLEASE!!!!! within the C++ Programming forums, part of the General Programming Boards category; I'm fairly new to programming & I keep getting this error "error C2447: '{' : missing function header (old-style formal ...

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    2

    Error help PLEASE!!!!!

    I'm fairly new to programming & I keep getting this error "error C2447: '{' : missing function header (old-style formal list?)" & I have no clue how to fix it if somebody could please help me I'd really appreciate it. Thanks

    I don't know how to tell what line the error is in so i put in all the code & all the error results.

    //************************************************** *******************
    //TITLE Lab 3.2
    //FILENAME: Lab 3.2.cpp
    //RELATED FILES(S) None
    //PREPARED FOR: CS115
    //PROFESSOR: Professor Larry Thomison
    //DESIGNER: Darrick Mohl
    //DEVELOPMENT DATE: 8/1/07
    //COMPILER USED: Microsoft Visual 2005
    //================================================== =================
    // REVISION HISTORY
    // List revisions made to the program (if applicable)
    // DATE PROGRAMMER DESCRIPTION OF CHANGES MADE
    // 4/4/00 Porter Version 2.0
    // 6/27/04 Johnson Version 3.0
    //************************************************** *********************************
    // THE BEGINNING OF THE PROGRAM
    //************************************************** *********************************

    #include <iostream> //tells which library that is used
    #include <cmath>

    using namespace std;

    float calculateCharges (float cost);

    void main() //the initializing of the main body of the program

    {
    float hour1, hour2, hour3, charge1, charge2, charge3, time, h_total, c_total;

    cout<< "Enter the hours for car 1: " << endl;
    cin>> hour1;

    cout<< "Enter the hours for car 2: " << endl;
    cin>> hour2;

    cout<< "Enter the hours for car 3: " << endl;
    cin>> hour3;

    charge1=calculateCharges(hour1);

    charge2=calculateCharges(hour2);

    charge3=calculateCharges(hour3);

    h_total=hour1+hour2+hour3;

    c_total=charge1+charge2+charge3;

    cout<< "Car "<< "Hours " << "Charge" << endl;
    cout<< "1 " << hour1 << charge1 << endl;
    cout<< "2 " << hour2 << charge2 << endl;
    cout<< "3 " << hour3 << charge3 << endl;
    cout<< "TOTAL " << h_total << c_total << endl;

    return;
    }

    float calculateCharges (float cost);
    {
    if (time <= 3);
    cost=2;
    return (cost);
    if (time > 3);
    cost=ceil(time-3)*0.5;
    return (cost);
    }


    1>------ Rebuild All started: Project: Lab 3 trial, Configuration: Debug Win32 ------
    1>Deleting intermediate and output files for project 'Lab 3 trial', configuration 'Debug|Win32'
    1>Compiling...
    1>Lab 3 trial.cpp
    1>.\Lab 3 trial.cpp(61) : error C2447: '{' : missing function header (old-style formal list?)
    1>Build log was saved at "file://c:\Documents and Settings\Mine\My Documents\Visual Studio 2005\Projects\Lab 3 trial\Lab 3 trial\Debug\BuildLog.htm"
    1>Lab 3 trial - 1 error(s), 0 warning(s)
    ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
    Last edited by seventh_sage; 08-02-2007 at 02:20 PM. Reason: code added

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    Post the code in [code][/code] tags and point to the line that has the error. If there is too much code to post, then post the lines above and below the line with the error.

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,801
    Code:
    float calculateCharges (float cost);
    {
    if (time <= 3);
    cost=2;
    return (cost);
    if (time > 3);
    cost=ceil(time-3)*0.5;
    return (cost);
    }
    Probably that stray semicolon (and the others that I've marked in red), get rid of them. Your remaining logic still needs work however. You're using a variable, time, that isn't in scope (or initialized).

    Oh... and main returns an int.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    You have an extra semicolon here. Get rid of it.
    Code:
    float calculateCharges (float cost);
    {
    if (time <= 3);
    cost=2;
    return (cost);
    if (time > 3);
    cost=ceil(time-3)*0.5;
    return (cost);
    }
    Only function prototypes have semicolons on the end, not declarations.

    [edit] Beaten, probably by only a few seconds . . . [/edit]

    Also, you shouldn't be using void main(); see the FAQ. faq.cprogramming.com/cgi-bin/smartfaq.cgi?id=1043284376&answer=1044841143
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Registered User
    Join Date
    Aug 2007
    Posts
    2
    Thanks you everybody for all of your help it looks like it will work now

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Code compiles - it must work ;-)

    --
    Mats

Popular pages Recent additions subscribe to a feed

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