-
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 ==========
-
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.
-
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.
-
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
-
Thanks you everybody for all of your help it looks like it will work now :) :) :)
-
Code compiles - it must work ;-)
--
Mats