I'm a newbie and I can't understand the errors in my program

This is a discussion on I'm a newbie and I can't understand the errors in my program within the C++ Programming forums, part of the General Programming Boards category; maybe i should just change my major! lol well...the exercise asks us to calculate charges for a parking garage. there's ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    19

    Unhappy I'm a newbie and I can't understand the errors in my program

    maybe i should just change my major! lol well...the exercise asks us to calculate charges for a parking garage. there's a $2.00 minimum fee for less than 3 hours, and a $0.50 charge for each additional hour, but the charge can't exceed $10.00. they want it in this kind of format:

    Car Hours Charges
    1 1.5 2.00
    2 4.0 2.50
    3 24.0 10.00
    TOTAL 29.5 14.50

    and this is what i have so far...laugh if u want...i'm so lost. i can't even tell if i've declared my variables right, or if my functions even work...i get continuous errors and don't know where to start. if there's any way anyone can help me, i'd greatly appreciate it.

    /* Calculate the total charges and the total hours for the parking garage. */

    #include <iostream>

    using std::cout;
    using std::cin;
    using std::endl;

    int charges (chargesa, chargesb, chargesc)
    int totalhours (a, b, c)
    int calculatecharges (chargesa, chargesb, chargesc)

    int main()
    {
    int a, b, c;

    cout<<"Enter the number of hours for CAR 1:";
    cin>>a;

    cout<<"Enter the number of hours for CAR 2:";
    cin>>b;

    cout<<"Enter the number of hours for CAR 3:";
    cin>>c;

    return 0;
    }

    int charges (chargesa,chargesb,chargesc)
    {
    int chargesa = a * 0.50
    if (a <= 3)
    chargesa = 2.00

    if (a > 3)
    chargesa = (a - 3) * 0.50

    if (chargesa >= 10.00)
    chargesa = 10.00

    int chargesb = b * 0.50
    if (b <= 3)
    chargesb = 2.00

    if (b > 3)
    chargesb = (b - 3) * 0.50

    if (chargesb >= 10.00)
    chargesb = 10.00

    int chargesc = c * 0.50
    if (c <= 3)
    chargesc = 2.00

    if (c > 3)
    chargesc = (c - 3) * 0.50

    if (chargesc >= 10.00)
    chargesc = 10.00

    cout<<"CAR 1 CHARGES:"<<chargesa;
    cout<<"CAR 2 CHARGES:"<<chargesb;
    cout<<"CAR 3 CHARGES:"<<chargesc;
    }

    int totalhours (a, b, c)
    {
    int totalhours = a + b + c
    }

    int calculatecharges (chargesa, chargesb, chargesc)
    {
    int calculatecharges = chargesa + chargesb + chargesc
    }


    P.S. - ur more than welcome to comment with ur opinion on whether or not i should change my major...especially after reading that code

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    [HINT] You never use ur functions. Also, you are missing a bunch of semicolons inside your functions. [/HINT]

    Also, check your formulas. i.e.

    chargesa = (a - 3) * 0.50 //don't forget the base charge of $2!!


    Come back with the rest when u have finished with that.

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    19

    ok this is what i have now

    /* Calculate the total charges and the total hours for the parking garage. */

    #include <iostream>

    using std::cout;
    using std::cin;
    using std::endl;

    int charges (chargesa, chargesb, chargesc)
    int totalhours (a, b, c)
    int calculatecharges (chargesa, chargesb, chargesc)

    int main()
    {
    int a, b, c;

    cout<<"Enter the number of hours for CAR 1:";
    cin>>a;

    cout<<"Enter the number of hours for CAR 2:";
    cin>>b;

    cout<<"Enter the number of hours for CAR 3:";
    cin>>c;

    return 0;
    }

    int charges (chargesa,chargesb,chargesc)
    {
    int chargesa = a * 0.50
    if (a <= 3)
    chargesa = 2.00;

    if (a > 3)
    chargesa = ((a - 3) * 0.50) + 2.00;

    if (chargesa >= 10.00)
    chargesa = 10.00;

    int chargesb = b * 0.50
    if (b <= 3)
    chargesb = 2.00;

    if (b > 3)
    chargesb = ((b - 3) * 0.50) + 2.00;

    if (chargesb >= 10.00)
    chargesb = 10.00;

    int chargesc = c * 0.50
    if (c <= 3)
    chargesc = 2.00;

    if (c > 3)
    chargesc = ((c - 3) * 0.50) + 2.00;

    if (chargesc >= 10.00)
    chargesc = 10.00;

    cout<<"CAR 1 CHARGES:"<<chargesa;
    cout<<"CAR 2 CHARGES:"<<chargesb;
    cout<<"CAR 3 CHARGES:"<<chargesc;
    }

    int totalhours (a, b, c)
    {
    int totalhours = a + b + c;
    }

    int calculatecharges (chargesa, chargesb, chargesc)
    {
    int calculatecharges = chargesa + chargesb + chargesc;
    }

    is that what u meant?

  4. #4
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Why do u have these here for everyone:

    int chargesa = a * 0.50/*this is not what the charges will be unless the number of hours is 20*/


    You still never use your functions!!!

    Code:
    //where do u use your functions??
    int main() 
    { 
      int a, b, c; 
    
      cout<<"Enter the number of hours for CAR 1:"; 
      cin>>a; 
    
      cout<<"Enter the number of hours for CAR 2:"; 
      cin>>b; 
    
      cout<<"Enter the number of hours for CAR 3:"; 
      cin>>c; 
    
      return 0; 
    }

    You do not have semicolons after your function prototypes.

  5. #5
    Registered User
    Join Date
    Jan 2002
    Posts
    19
    well sorrrrrryyyy!!!! i told u that i know absolutely nothing about this type of programming. no need to act like that. it'd be nice if someone could explain what's wrong but obviously that's not the case.

  6. #6
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Relax there, I wasn't screaming at you and I am not mad at u.


    When I say u never use your functions, I mean that you create them but you never actually call them. For them to actually be executed, you have to tell the program to use them inside the main part. So after all the data is inputted and before return 0, call your functions with the inputted data.

  7. #7
    Registered User
    Join Date
    Jan 2002
    Posts
    19
    so can i put them n e where in main like this:

    int main()
    {
    int a;
    b;
    c;

    cout<<"Enter the number of hours for CAR 1:";
    cin>>a;

    cout<<"Enter the number of hours for CAR 2:";
    cin>>b;

    cout<<"Enter the number of hours for CAR 3:";
    cin>>c;

    int charges (chargesa, chargesb, chargesc)
    int totalhours (a, b, c)
    int calculatecharges (chargesa, chargesb, chargesc)

    return 0;
    }

    sorry for going off earlier. its been an extremely rough day and i've spent hours and hours on this program but i can't figure it out. its driving me crazy cuz i can't ever get the help i need from my classmates or my teacher...i'm just extremely confused and really really tired, but hopefully i'll get it.

  8. #8
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    If you make the first line int a,b,c; again and you put semicolons after your function calls inside of main it should work, but the output won't be formatted right.

    P.S. Don't worry about it. Everyone has bad days.

  9. #9
    Registered User
    Join Date
    Jan 2002
    Posts
    19
    i guess that getting the program to work is my priority...but how would i change the couts to get the output to line up?

  10. #10
    Registered User
    Join Date
    Jan 2002
    Posts
    19
    well i've changed it, but i still can't get it to work...here's what i have:

    /* Calculate the total charges and the total hours for the
    parking garage. */

    #include <iostream>

    using std::cout;
    using std::cin;
    using std::endl;

    int charges (chargesa, chargesb, chargesc)
    int totalhours (a, b, c)
    int calculatecharges (chargesa, chargesb, chargesc)

    int main()
    {
    int a, b, c;

    cout<<"Enter the number of hours for CAR 1:";
    cin>>a;

    cout<<"Enter the number of hours for CAR 2:";
    cin>>b;

    cout<<"Enter the number of hours for CAR 3:";
    cin>>c;

    int charges (chargesa, chargesb, chargesc);
    int totalhours (a, b, c);
    int calculatecharges (chargesa, chargesb, chargesc);

    return 0;
    }

    int charges (chargesa,chargesb,chargesc)
    {
    int chargesa
    if (a <= 3)
    chargesa = 2.00;

    if (a > 3)
    chargesa = ((a - 3) * 0.50) + 2.00;

    if (chargesa >= 10.00)
    chargesa = 10.00;

    int chargesb
    if (b <= 3)
    chargesb = 2.00;

    if (b > 3)
    chargesb = ((b - 3) * 0.50) + 2.00;

    if (chargesb >= 10.00)
    chargesb = 10.00;

    int chargesc
    if (c <= 3)
    chargesc = 2.00;

    if (c > 3)
    chargesc = ((c - 3) * 0.50) + 2.00;

    if (chargesc >= 10.00)
    chargesc = 10.00;

    cout<<"CAR 1 CHARGES:"<<chargesa;
    cout<<"CAR 2 CHARGES:"<<chargesb;
    cout<<"CAR 3 CHARGES:"<<chargesc;
    }

    int totalhours (a, b, c)
    {
    int totalhours = a + b + c;
    }

    int calculatecharges (chargesa, chargesb, chargesc)
    {
    int calculatecharges = chargesa + chargesb + chargesc;
    }

    if u can come up with anymore conclusions, please let me know. i'm gonna call it a nite...but i'll check back first thing in the morning if u come up with n e thing...thanks so much for the help

  11. #11
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    I'm calling it a night too, I'll help you tommorrow if no one else does by then.

  12. #12
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408

    Kapoof

    Code:
    if (chargesb >= 10.00) 
    chargesb = 10.00; 
    
    int chargesc 
    if (c <= 3) 
    chargesc = 2.00; 
    
    if (c > 3) 
    chargesc = ((c - 3) * 0.50) + 2.00; 
    
    if (chargesc >= 10.00) 
    chargesc = 10.00; 
    
    cout<<"CAR 1 CHARGES:"<<chargesa; 
    cout<<"CAR 2 CHARGES:"<<chargesb; 
    cout<<"CAR 3 CHARGES:"<<chargesc;
    Aren't you forgetting a bunch of { and }?
    Or maybe you dont need them.....
    I'm pretty newbie too so....

  13. #13
    Registered User skillet's Avatar
    Join Date
    Feb 2002
    Posts
    20
    hey... I was going over golf's profile because he had been helping me, and ended up here. Being a fellow Okie, I thought I'd drop a few comments in for afboys to consider on her program:

    1. the function prototypes at the top of your program (charges, totalhours and calculatecharges) don't need the actual variable in the parameter list, just the TYPE for the parameters-- on the same note, the function definitions at the end of your program will need the type AND the variable name in the parameter list.

    2. Make sure that if you say a function is going to return a value, that it DOES return a value in the function definition.

    I think after I fixed these two items in the code you posted (plus a few semicolons here and there), that the program compiles for me. You will probably want to change a few things for the output once you get your code running...

  14. #14
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    Go through your books on declaring and using functions - that'll help you a lot.

    Code:
    /* Calculate the total charges and the total hours for the 
    parking garage. */ 
    
    #include <iostream> 
    
    using std::cout; 
    using std::cin; 
    using std::endl; 
    
    //These are prototypes (look it up) - they need semicolons
    
    void calculatecharges (int hoursa, int hoursb, int hoursc);
    
    int main() 
    { 
    int a, b, c; 
    
    cout<<"Enter the number of hours for CAR 1:"; 
    cin>>a; 
    
    cout<<"Enter the number of hours for CAR 2:"; 
    cin>>b; 
    
    cout<<"Enter the number of hours for CAR 3:"; 
    cin>>c; 
    
    calculatecharges(a, b, c);
    
    return 0; 
    } 
    
    void calculatecharges(int hoursa, int hoursb, int hoursc)
    {
       int costa = 0;
       int costb = 0;
       int costc = 0;
      
       if(hoursa <= 3)
            costa = 2;
       else if (hoursa >= 17)
            costa = 10;
       else
            costa = 2 + ((hoursa-3) * .5);
    
       if(hoursb <= 3)
            costb = 2;
       else if (hoursb >= 17)
            costb = 10;
       else
            costb = 2 + ((hoursa-3) * .5);
    
       if(hoursc <= 3)
            costc = 2;
       else if (hoursc >= 17)
            costc = 10;
       else
            costc = 2 + ((hoursc-3) * .5);
    
        cout<<"CAR 1 CHARGES: "<<costa<<endl; 
        cout<<"CAR 2 CHARGES: "<<costb<<endl; 
        cout<<"CAR 3 CHARGES: "<<costc<<endl; 
    }

  15. #15
    Registered User
    Join Date
    Jan 2002
    Posts
    19
    the program still doesn't work. it says that :

    man.cpp: In function `void calculatecharges(int, int, int)':
    man.cpp:41: warning: assignment to `int' from `double'
    man.cpp:48: warning: assignment to `int' from `double'
    man.cpp:55: warning: assignment to `int' from `double'

    and this is the program that i've got now:

    /* Calculate the total charges and the total hours for the
    parking garage. */

    #include <iostream>

    using std::cout;
    using std::cin;
    using std::endl;

    void calculatecharges (int hoursa, int hoursb, int hoursc);

    int main()
    {
    int a, b, c;

    cout<<"Enter the number of hours for CAR 1:";
    cin>>a;

    cout<<"Enter the number of hours for CAR 2:";
    cin>>b;

    cout<<"Enter the number of hours for CAR 3:";
    cin>>c;

    calculatecharges(a, b, c);

    return 0;
    }

    void calculatecharges(int hoursa, int hoursb, int hoursc)
    {
    int costa = 0;
    int costb = 0;
    int costc = 0;

    if(hoursa <= 3)
    costa = 2.00;
    else if (hoursa >= 17)
    costa = 10.00;
    else
    costa = 2 + ((hoursa-3) * .5);

    if(hoursb <= 3)
    costb = 2.00;
    else if (hoursb >= 17)
    costb = 10.00;
    else
    costb = 2 + ((hoursa-3) * .5);

    if(hoursc <= 3)
    costc = 2.00;
    else if (hoursc >= 17)
    costc = 10.00;
    else
    costc = 2 + ((hoursc-3) * .5);

    cout<<"CAR 1 CHARGES: "<<costa<<endl;
    cout<<"CAR 2 CHARGES: "<<costb<<endl;
    cout<<"CAR 3 CHARGES: "<<costc<<endl;
    }

    and i still don't see how the total hours will be displayed?

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21