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)

'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.
{
<stuff>
}

'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.
{
<stuff>
}

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

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.

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

Edited 3 Years Ago by happygeek: fixed formatting

// (30 lines)
    if (charge>10)		// flat rate of 10 dollars is charged
    charge=10;
    return charge;
    }
    
   [b] {[/b] // 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?

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 <iostream>
#include <iomanip>
#include <ctime>
#include <cstdlib>


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<CARS;i++)
{
cout << "How long was car " <<(i+1)<<" parked? ";
cin >> hours;
}
//print header
cout << endl;
cout << "Car\tHours\tCharge" << endl;
// for each car
for(i=0;i<CARS;i++)
{
// get amount owed
charge = calculateCharges (hours);
// display charges
// car
cout << (i+1);
// hours
cout << setprecision ( 1 );
cout << hours;
// charges
cout << setprecision ( 2 );
cout << charge << endl;
// add to daily totals
thours+=hours;
tcharge+=charge;
}
// print totals
cout << "Total" << thours << tcharge << endl;
return 0;
}

Edited 3 Years Ago by Nick Evan: Fixed formatting

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;
}

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]!)

Comments
always able to give good advice about programming. --KT

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

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..

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:

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

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.

This article has been dead for over six months. Start a new discussion instead.