| | |
What does this mean?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2004
Posts: 11
Reputation:
Solved Threads: 0
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)
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>
}
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>
}
•
•
Join Date: Sep 2004
Posts: 11
Reputation:
Solved Threads: 0
•
•
•
•
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>
}
i will try it, but if i desinate int hour = 2; does that limit the amount of hours that int could be
•
•
Join Date: Sep 2004
Posts: 11
Reputation:
Solved Threads: 0
•
•
•
•
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.
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
•
•
•
•
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
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
•
•
Join Date: Sep 2004
Posts: 11
Reputation:
Solved Threads: 0
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;
}
#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;
}
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)
#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
![]() |
Other Threads in the C++ Forum
- Previous Thread: C++ handling of strings in a boolean expression
- Next Thread: Giving me hadaches
| Thread Tools | Search this Thread |
api array beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion count data database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game getline google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text text-file tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






