>>costa = 2.00;
You are assigning a literal double to an int
try costa = 2
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...
>>costa = 2.00;
You are assigning a literal double to an int
try costa = 2
> 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; }
-Govtcheez
govtcheez03@hotmail.com
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!
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
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...