Ask Experts Questions for FREE Help !
Ask
    jess62585's Avatar
    jess62585 Posts: 2, Reputation: 1
    New Member
     
    #1

    Apr 26, 2009, 06:19 PM
    stuck with creating a paking program
    #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's Avatar
    Perito Posts: 3,139, Reputation: 150
    Ultra Member
     
    #2

    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's Avatar
    jess62585 Posts: 2, Reputation: 1
    New Member
     
    #3

    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's Avatar
    Perito Posts: 3,139, Reputation: 150
    Ultra Member
     
    #4

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

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

How is she creating these? [ 3 Answers ]

Hi my name is Aly Kaee I have been getting into photography lately and I have recently been very inspired by a photographer named Rosie Hardy But I was wondering how does she do her photos? How does she do the background, Attach strings to birds, How does she get the textures in the sky,...

What is the steps of creating Complete Program? [ 5 Answers ]

Is there anybody who can help me to create program like receiving, issuing, monthly reporting and inventory program? Just I need the proper organizing. I am just beginner of visual basic. I hope somebody can help me. Thanks in advance

Huge program, and I'm stuck and its frustrating me so [ 5 Answers ]

right OK, it doesn't like the String winner = (whatever) bits at the bottom and I don't know why, please can anybody help me... PLEASE!! import java.util.*; class MyProblem { public static void main ( String args) {

Web creating [ 1 Answers ]

I want to have my own website ,I tried to have it ,but I can't get a free website creating address. Please, is there anyone who can help me?and can you tell me what I have to do step by steps?please it is serious. ...

Program for creating database [ 3 Answers ]

Hello! I have one question: I want to create a database which would act like stand alone program (I hope you understand). So far so good but the problem is that I don't know any of programming languages so I need a program which doesn't require programming. If anybody knows program like that...


View more questions Search