Log in

View Full Version : Stuck with creating a paking program


jess62585
Apr 26, 2009, 06:19 PM
#include<iostream>
#include<iomanip>
using namespace std;
const double enter_park = 2.00;
const double after_three_hours =0.50;
double calculateCharges(int hours, double cost, double a);
int main()
{
double cost;
double hours;
double a;
double b;
double c;

cout << fixed << showpoint;
cout << setprecision (2);
cout << "Enter the hours that the car spent in the parking lot.";
cin >> b;
calculateCharges(double b, double c, double a);
cout << b << " $" <<c << endl;
cin >> hours;
calculateCharges (double b,double c,double a);
cout << b <<" $" <<c <<endl;
return 0;
}
double calculateCharges(int hours, double cost,double a)
{if (hours <= 3)
enter_park;
else
a=hours - 3;
cost = enter_park + after_three_hours * a;
if (hours <= 12)
cost = 10.00;
return cost;
}
What do I need to do to get this to run right
Jess

Perito
Apr 29, 2009, 09:29 AM
calculateCharges(double b, double c, double a);

You don't seem to be passing any values here. It should be something like:

calculateCharges(hours, b, a)

and you don't need the 'double' except in the declaration.

jess62585
May 2, 2009, 08:43 PM
#include<iostream>
#include<iomanip>
using namespace std;
const double enter_park = 2.00;
const double after_three_hours =0.50;
double calculateCharges(double hours, double cost, double a);
int main()
{
double car1;
double car2;
double car3;
double b;
double c;
cout << fixed << showpoint;
cout << setprecision (2);
cout << "Enter the hours that the car spent in the parking lot.";
cin >> car1 >> calculateCharges(car1 ,b);
cout << endl;
cout << " Enter the seconds cars hours";
cin >> car2 >> calculateCharges(car2, b) >> endl;
cout << "Enter the third cars hours";
cin >> car3 >> calculateCharges(car3,b) >> endl;
c= car3+car2+car1;

cout << car1 <<" $" << b << endl;
cout << car2 <<" $" << b << endl;
cout << car3 <<" $" << b << endl;
return 0;

}
double calculateCharges(double hours, double cost)
double a;
{
if (hours <= 3)
{
cost=enter_park;
}
else
{
a=hours - 3;
cost = enter_park + after_three_hours * a;
}
if (hours >= 12)
{
cost = 10.00;
return cost;}
}
here is my revised copy I need help knowing where to put the calculateCharges in the main function.

Perito
May 3, 2009, 05:20 AM
cout << fixed << showpoint;
cout << setprecision (2);
cout << "Enter the hours that the car spent in the parking lot.";
cin >> car1 >> calculateCharges(car1 ,b);
cout << endl;
cout << " Enter the seconds cars hours";
cin >> car2 >> calculateCharges(car2, b) >> endl;
cout << "Enter the third cars hours";
cin >> car3 >> calculateCharges(car3,b) >> endl;
c= car3+car2+car1;


In your original program, calculateCharges appeared to be in a reasonable place. I'm not sure why you had it there twice.

I'm not sure why you put "cin >> car1 >> calculateCharges(car1 ,b);" instead of having it on two lines. It's much clearer if you put it on two lines.

How about something like this? (there are better alternatives to getting information than using cin). You fill hours, minutes, seconds with the time the car spent in the parking lot. You could put this into a "secondsInParkingLot" variable -- a floating point number with hours and minutes both converted to seconds and added along with seconds (secondsInParkingLot = hours * 3600 + minutes * 60 + seconds). You could also go with fractional hours.

double hours;
double minutes;
double seconds;
...
cin>>hours;
cin>>minutes;
cin>>seconds; // you could simply enter time as a string, "hh:mm:ss", and convert that to hours, minutes, and seconds.
hours = hours + minutes / 60.0 + seconds / 3600.0
cost = calculateCharges(hours)

double calculateCharges(double hours) // you don't need to pass "cost"
double a;
double cost;
{
if (hours <= 3)
{
cost=enter_park;
}
else
{
a=hours - 3;
totalcost = enter_park + after_three_hours * a;
}
if (hours >= 12)
{
cost = 10.00;
return cost;}
}