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; >>costa = 2.00; You are assigning a literal double to an int try costa = 2...

  1. #16
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    >>costa = 2.00;


    You are assigning a literal double to an int

    try costa = 2

  2. #17
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    > and i still don't see how the total hours will be displayed?

    My mistake - they won't... I didn't read your problem close enough.

    The warnings are my fault - everything should be double to take care of fractions of an hour or fractions of a dollar
    Code:
    /* 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 (double hoursa, double hoursb, double hoursc);
    
    int main() 
    { 
    double 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(double hoursa, double hoursb, double hoursc)
    {
       double costa = 0;   
       double costb = 0;
       double costc = 0;
       double totalhours = 0;
       double totalcost = 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);
        
        totalhours = hoursa + hoursb + hoursc;
        totalcost = costa + costb + costc;
        cout<<"CAR 1 CHARGES: "<<costa<<endl; 
        cout<<"CAR 2 CHARGES: "<<costb<<endl; 
        cout<<"CAR 3 CHARGES: "<<costc<<endl; 
        cout<<"TOTAL: "<<totalhours<< " hours, $"<<totalcost<<endl;
    }

  3. #18
    Registered User
    Join Date
    Jan 2002
    Posts
    19
    THANKS SO MUCH! all of u have been such a great help. i think i'm gonna try to find C++ for dummies....i hear that's a good book to read. thanks again!

  4. #19
    Registered User
    Join Date
    Jan 2002
    Posts
    19
    i don't know....i just ran the program, and it still doesn't work...i get this:

    /tmp/ccUHX0O8.o: In function `main':
    /tmp/ccUHX0O8.o(.text+0xa0): undefined reference to `calculatecharges(double, d'
    collect2: ld returned 1 exit status

  5. #20
    Registered User
    Join Date
    Feb 2002
    Posts
    27
    I am doing the same excercise...

    except i use for loops for my customer

    I tested your program and it runs fine. I don't know why u can't get it run. Make sure everything is right, header syntax etc...

Page 2 of 2 FirstFirst 12
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