943,513 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 6513
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Sep 6th, 2004
2

What does this mean?

Expand Post »
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)
Reputation Points: 13
Solved Threads: 0
Newbie Poster
big buc's fan is offline Offline
11 posts
since Sep 2004
Sep 6th, 2004
0

Re: What does this mean?

'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>
}
Reputation Points: 36
Solved Threads: 11
Posting Pro in Training
Chainsaw is offline Offline
436 posts
since Jun 2004
Sep 6th, 2004
0

Re: What does this mean?

Quote 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
Reputation Points: 13
Solved Threads: 0
Newbie Poster
big buc's fan is offline Offline
11 posts
since Sep 2004
Sep 6th, 2004
0

Re: What does this mean?

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.
Reputation Points: 36
Solved Threads: 11
Posting Pro in Training
Chainsaw is offline Offline
436 posts
since Jun 2004
Sep 6th, 2004
0

Re: What does this mean?

Quote 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
Reputation Points: 13
Solved Threads: 0
Newbie Poster
big buc's fan is offline Offline
11 posts
since Sep 2004
Sep 6th, 2004
0

Re: What does this mean?

Quote 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?
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Sep 6th, 2004
0

Re: What does this mean?

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;
}
Reputation Points: 13
Solved Threads: 0
Newbie Poster
big buc's fan is offline Offline
11 posts
since Sep 2004
Sep 6th, 2004
2

Re: What does this mean?

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;
}
Reputation Points: 15
Solved Threads: 0
Newbie Poster
XianBin is offline Offline
24 posts
since Aug 2004
Sep 6th, 2004
1

Re: What does this mean?

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]!)
Reputation Points: 36
Solved Threads: 11
Posting Pro in Training
Chainsaw is offline Offline
436 posts
since Jun 2004
Sep 7th, 2004
2

Re: What does this mean?

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

C++ Syntax (Toggle Plain Text)
  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
Reputation Points: 14
Solved Threads: 0
Newbie Poster
big146 is offline Offline
18 posts
since Jul 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: C++ handling of strings in a boolean expression
Next Thread in C++ Forum Timeline: Giving me hadaches





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC