What does this mean?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2004
Posts: 11
Reputation: big buc's fan is an unknown quantity at this point 
Solved Threads: 0
big buc's fan big buc's fan is offline Offline
Newbie Poster

What does this mean?

 
2
  #1
Sep 6th, 2004
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)
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 436
Reputation: Chainsaw is an unknown quantity at this point 
Solved Threads: 10
Chainsaw's Avatar
Chainsaw Chainsaw is offline Offline
Unprevaricator

Re: What does this mean?

 
0
  #2
Sep 6th, 2004
'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>
}
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 11
Reputation: big buc's fan is an unknown quantity at this point 
Solved Threads: 0
big buc's fan big buc's fan is offline Offline
Newbie Poster

Re: What does this mean?

 
0
  #3
Sep 6th, 2004
Originally Posted by Chainsaw
'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
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 436
Reputation: Chainsaw is an unknown quantity at this point 
Solved Threads: 10
Chainsaw's Avatar
Chainsaw Chainsaw is offline Offline
Unprevaricator

Re: What does this mean?

 
0
  #4
Sep 6th, 2004
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 11
Reputation: big buc's fan is an unknown quantity at this point 
Solved Threads: 0
big buc's fan big buc's fan is offline Offline
Newbie Poster

Re: What does this mean?

 
0
  #5
Sep 6th, 2004
Originally Posted by Chainsaw
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,346
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 237
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: What does this mean?

 
0
  #6
Sep 6th, 2004
Originally Posted by big buc's fan
				 // (30 lines)
    if (charge>10)		// flat rate of 10 dollars is charged
    charge=10;
    return charge;
    }
    
    { // 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?
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 11
Reputation: big buc's fan is an unknown quantity at this point 
Solved Threads: 0
big buc's fan big buc's fan is offline Offline
Newbie Poster

Re: What does this mean?

 
0
  #7
Sep 6th, 2004
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[i];
}
//print header
cout << endl;
cout << "Car\tHours\tCharge" << endl;
// for each car
for(i=0;i<CARS;i++)
{
// get amount owed
charge = calculateCharges (hours[i]);
// display charges
// car
cout << (i+1);
// hours
cout << setprecision ( 1 );
cout << hours[i];
// charges
cout << setprecision ( 2 );
cout << charge << endl;
// add to daily totals
thours+=hours[i];
tcharge+=charge;
}
// print totals
cout << "Total" << thours << tcharge << endl;
return 0;
}
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 24
Reputation: XianBin is an unknown quantity at this point 
Solved Threads: 0
XianBin XianBin is offline Offline
Newbie Poster

Re: What does this mean?

 
2
  #8
Sep 6th, 2004
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;
}
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 436
Reputation: Chainsaw is an unknown quantity at this point 
Solved Threads: 10
Chainsaw's Avatar
Chainsaw Chainsaw is offline Offline
Unprevaricator

Re: What does this mean?

 
1
  #9
Sep 6th, 2004
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]!)
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 18
Reputation: big146 is an unknown quantity at this point 
Solved Threads: 0
big146's Avatar
big146 big146 is offline Offline
Newbie Poster

Re: What does this mean?

 
2
  #10
Sep 7th, 2004
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).

  1. #include <iostream>
  2.  
  3. using std::cout;
  4. using std::endl;
  5. using std::cin;
  6. using std::fixed;
  7.  
  8. #include <iomanip>
  9.  
  10. using std::setw;
  11. using std::setprecision;
  12.  
  13. #include <cmath>
  14.  
  15. double calculateCharges( double );
  16.  
  17. int main()
  18. {
  19. double hour; // hours parked for each car
  20. double currentCharge; // current parking charge
  21. double totalCharges = 0.0; // total charges
  22. double totalHours = 0.0; // total hours
  23.  
  24. cout << "Enter the hours parked for three cars: ";
  25.  
  26. for ( int i = 1; i <= 3; i++ ) {
  27. cin >> hour;
  28. totalHours += hour;
  29.  
  30. if ( i == 1 ) {
  31. cout << setw( 5 ) << "Car" << setw( 15 ) << "Hours"
  32. << setw( 15 ) << "Charge\n";
  33.  
  34. } // end if
  35.  
  36. totalCharges += ( currentCharge =
  37. calculateCharges( hour ) );
  38.  
  39. cout << fixed << setw( 3 ) << i << setw( 17 )
  40. << setprecision( 1 ) << hour
  41. << setw( 15 ) << setprecision( 2 )
  42. << currentCharge << "\n";
  43.  
  44. } // end for
  45.  
  46. cout << setw( 7 ) << "TOTAL" << setw( 13 ) << setprecision( 1 )
  47. << totalHours << setw( 15 ) << setprecision( 2 )
  48. << totalCharges << endl;
  49.  
  50. return 0;
  51.  
  52. } // end main
  53.  
  54. // calculate charges for hours parked
  55. double calculateCharges( double hours )
  56. {
  57. double charge;
  58.  
  59. if ( hours < 3.0 )
  60. charge = 2.0;
  61. else if ( hours < 19.0 )
  62. charge = 2.0 + .5 * ceil( hours - 3.0 );
  63. else
  64. charge = 10.0;
  65.  
  66. return charge;
  67.  
  68. } // end function calculateCharges
big146
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC