954,141 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

What does this mean?

This might be a oversight by me but when I compile and the programs runs I get this error:park.cpp(11) : error C2065:'hours' : undeclared identifier
if (hours<=3) this is code from my program

park.cpp(34) : error C2447: missing function header (old-style formal list?)
What is this------->(old-style formal list?)

Maybe I'm brain farting, but this is really putting a stop on progress. Was i susposed to declare hours as a interger or variable and i did i forget a bracket somewhere
thanks for any direction (I know this will help me become a PE teacher)

big buc's fan
Newbie Poster
11 posts since Sep 2004
Reputation Points: 13
Solved Threads: 0
 

'hours' undeclared means you did not declare it as an int....

int hours = 2;
if (hours <= 3) ...

an old style formal list is almost never used anymore, but compilers freak out when you put a semicolon on the declaration and give that error:

void foo(int n); // the semicolon makes the compiler angry. Remove it.
{

}

Chainsaw
Posting Pro in Training
436 posts since Jun 2004
Reputation Points: 36
Solved Threads: 11
 

'hours' undeclared means you did not declare it as an int....

int hours = 2; if (hours <= 3) ...

an old style formal list is almost never used anymore, but compilers freak out when you put a semicolon on the declaration and give that error:

void foo(int n); // the semicolon makes the compiler angry. Remove it. { }


Thanks for the help
i will try it, but if i desinate int hour = 2; does that limit the amount of hours that int could be

big buc's fan
Newbie Poster
11 posts since Sep 2004
Reputation Points: 13
Solved Threads: 0
 

Well, I'm not sure where the hours comes from, but it appears to be a number the way you are using it, so your choices are basically int, unsigned int, float, and double. As long as you declare it as one of those the compiler should be happier.

Chainsaw
Posting Pro in Training
436 posts since Jun 2004
Reputation Points: 36
Solved Threads: 11
 
Well, I'm not sure where the hours comes from, but it appears to be a number the way you are using it, so your choices are basically int, unsigned int, float, and double. As long as you declare it as one of those the compiler should be happier.


yea it clear it up once i declared hours

However that error of this is dumbfound to me
error C2447: missing function header (old-style formal list?)
on you previous help i look up previous code lines and basically i open and closed brackets....this is a piece of the code from line 30 to 37 which the error comes from, it looks right to me and thats probably the reason I'm missing something?? i only be at this for about 6 hours.....thanks again

// (30 lines)
if (charge>10) // flat rate of 10 dollars is charged
charge=10;
return charge;
}

{
double hours[CARS]; // store hours parked by the different cars

big buc's fan
Newbie Poster
11 posts since Sep 2004
Reputation Points: 13
Solved Threads: 0
 
// (30 lines)
    if (charge>10)		// flat rate of 10 dollars is charged
    charge=10;
    return charge;
    }
    
   <strong> {</strong> // What is this doing here?
 double hours[CARS]; // store hours parked by the different cars

I believe your compiler is asking the same question.

If the whole code is less than 100 lines, why not post the whole thing and avoid playing 20 questions?

Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

i was trying to avoid having one bash me for putting the whole code, however i always had thick skin and could tack the bashing... but here the whole code, hope i'm not stepping over my privileges for help;-)
#include
#include
#include
#include

using namespace std;

const int CARS = 3; //number of cars parked yesterday (8LINES)
//function used to calculate parking charges double calculate Charges
int main()
{
double charge; // charge minnimum rate of 2 dollars for 3 hours
int hours;
if (hours<=3)

{
charge=2;
}
// hours > 3
else
{
charge=2; // charge base rate of 2 dollars
hours-=3; // check how long over 3 hours the car was parked
while(hours>0)
{
charge+=.5; // charge 50 cents for extra hours
hours--; // hour or part of was charged (27LINES)
}
}
// (30 lines)
if (charge>10) // flat rate of 10 dollars is charged
charge=10;
return charge;
}

{
double hours[CARS]
double thours=0, tcharge=0, charge; // stores daily totals and total for a car
int i;

cout << "Parking Garage" << endl;
// get hours parked
for(i=0; i> hours[i];
}
//print header
cout << endl;
cout << "Car\tHours\tCharge" << endl;
// for each car
for(i=0;i

big buc's fan
Newbie Poster
11 posts since Sep 2004
Reputation Points: 13
Solved Threads: 0
 

int main()
{
double charge; // charge minnimum rate of 2 dollars for 3 hours
int hours;

//----------------------------
// Add a input statement

cin >> hours;

//----------------------------

if (hours<=3)

{
charge=2;
}

XianBin
Newbie Poster
24 posts since Aug 2004
Reputation Points: 15
Solved Threads: 0
 

It looks like the part starting with

{
double hours[CARS]

is intended to be the main() routine? And then it calls that other routine and passes in hours?

(also, don't forget the semicolon after [CARS]!)

Chainsaw
Posting Pro in Training
436 posts since Jun 2004
Reputation Points: 36
Solved Threads: 11
 

I think what you want is somethng like this...(by the way I looked at your profile so i know you are not a kid working on homework).

#include <iostream> 

using std::cout; 
using std::endl; 
using std::cin; 
using std::fixed;

#include <iomanip>
 
using std::setw; 
using std::setprecision; 

#include <cmath>

double calculateCharges( double );

int main()
{
   double hour; // hours parked for each car
   double currentCharge; // current parking charge
   double totalCharges = 0.0; // total charges   
   double totalHours = 0.0; // total hours

   cout << "Enter the hours parked for three cars: ";

   for ( int i = 1; i <= 3; i++ ) {
      cin >> hour;
      totalHours += hour;
   
      if ( i == 1 ) {
         cout << setw( 5 ) << "Car" << setw( 15 ) << "Hours"
              << setw( 15 ) << "Charge\n";

      } // end if
   
      totalCharges += ( currentCharge = 
         calculateCharges( hour ) );

      cout << fixed << setw( 3 ) << i << setw( 17 )
           << setprecision( 1 ) << hour
           << setw( 15 ) << setprecision( 2 )
           << currentCharge << "\n";
   
   } // end for

   cout << setw( 7 ) << "TOTAL" << setw( 13 ) << setprecision( 1 )
        << totalHours << setw( 15 ) << setprecision( 2 )
        << totalCharges << endl;

   return 0;

} // end main

// calculate charges for hours parked
double calculateCharges( double hours )
{
   double charge;

   if ( hours < 3.0 )
      charge = 2.0;
   else if ( hours < 19.0 )
      charge = 2.0 + .5 * ceil( hours - 3.0 );
   else
      charge = 10.0;
   
   return charge;

} // end function calculateCharges
big146
Newbie Poster
18 posts since Jul 2004
Reputation Points: 14
Solved Threads: 0
 

thanks for all the help that gave me help ;-)
the only question if i get the code of::: error C2447: missing function header (old-style formal list?) does that mean i missed a bracket, or was i suspposed to do something else i think i might of mixed up open and closeing brackets but i not the best with codeing just trying my luck and self teaching..

big buc's fan
Newbie Poster
11 posts since Sep 2004
Reputation Points: 13
Solved Threads: 0
 

I think what you want is somethng like this...(by the way I looked at your profile so i know you are not a kid working on homework).

#include <iostream> 

using std::cout; 
using std::endl; 
using std::cin; 
using std::fixed;

#include <iomanip>
 
using std::setw; 
using std::setprecision; 

#include <cmath>

double calculateCharges( double );

int main()
{
   double hour; // hours parked for each car
   double currentCharge; // current parking charge
   double totalCharges = 0.0; // total charges   
   double totalHours = 0.0; // total hours

   cout << "Enter the hours parked for three cars: ";

   for ( int i = 1; i <= 3; i++ ) {
      cin >> hour;
      totalHours += hour;
   
      if ( i == 1 ) {
         cout << setw( 5 ) << "Car" << setw( 15 ) << "Hours"
              << setw( 15 ) << "Charge\n";

      } // end if
   
      totalCharges += ( currentCharge = 
         calculateCharges( hour ) );

      cout << fixed << setw( 3 ) << i << setw( 17 )
           << setprecision( 1 ) << hour
           << setw( 15 ) << setprecision( 2 )
           << currentCharge << "\n";
   
   } // end for

   cout << setw( 7 ) << "TOTAL" << setw( 13 ) << setprecision( 1 )
        << totalHours << setw( 15 ) << setprecision( 2 )
        << totalCharges << endl;

   return 0;

} // end main

// calculate charges for hours parked
double calculateCharges( double hours )
{
   double charge;

   if ( hours < 3.0 )
      charge = 2.0;
   else if ( hours < 19.0 )
      charge = 2.0 + .5 * ceil( hours - 3.0 );
   else
      charge = 10.0;
   
   return charge;

} // end function calculateCharges

question when i try to run you code how come it doesn't say on the screen so i came see what come out?
thanks for the example code it helps me learn this hobby :cheesy:

big buc's fan
Newbie Poster
11 posts since Sep 2004
Reputation Points: 13
Solved Threads: 0
 
question when i try to run you code how come it doesn't say on the screen so i came see what come out? thanks for the example code it helps me learn this hobby :cheesy:


sorry about the spell check i miss a couple of letters it should read " when i try to run your code how come it doesn't stay on the screen so i can see what the outcome is?"
thanks again from a bad speller

big buc's fan
Newbie Poster
11 posts since Sep 2004
Reputation Points: 13
Solved Threads: 0
 
sorry about the spell check i miss a couple of letters it should read " when i try to run your code how come it doesn't stay on the screen so i can see what the outcome is?" thanks again from a bad speller



open up dos and navigate to the program and run it, then it will stay on the screen. there is also a fix for this too, that will wait for one last piece of input for the user before it closes. but i dont remember the syntax or the command.

Killer_Typo
Master Poster
781 posts since Apr 2004
Reputation Points: 152
Solved Threads: 39
 

Just put a

cin.get()


at the end of the code, exactly before

return 0


command...

frrossk
Posting Whiz in Training
220 posts since Sep 2004
Reputation Points: 17
Solved Threads: 9
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You