[フレーム]
Last Updated: November 08, 2017
·
323
· tony66Wasp

C language exercise

I have created this program which purpose is to calculate the charge of a parking for cars, for three cars which park there: 2,00ドル for 3 hours, 0,50ドル for every more hour over 3h, or a fraction of it. And 10ドル for 24h. Let's suppose none of them parks there for more than 24h.
I coded the program but when I compile it, it continues to give me this message: "undefined referece to 'calculateCharge'".
Someone knows how to resolve it?

/Program that calculates the charge/

include <stdio.h>

include <math.h>

float calculateCharge(float, float); /*function prototype */

main()
{
float totalHour, totalCharge, hour1, hour2, hour3, charge1, charge2, charge3;
int car=1;

printf("Car Hours Charge");

while(car != 3)
{
 switch(car)
 {
 case 1:
 printf("%d ", car);
 scanf("%.2f", &hour1);
 printf(" %.2f", calculateCharge(hour1, charge1));
 car ++;
 break;

 case 2:
 printf("%d ", car);
 scanf("%.2f", &hour2);
 printf(" %.2f", calculateCharge(hour2, charge2));
 car ++;
 break;

 case 3:
 printf("%d ", car);
 scanf("%.2f", &hour3);
 printf(" %.2f", calculateCharge(hour3, charge3));
 car ++;
 break;
 } /*end of switch*/
} /*end of while*/

printf("TOTAL");

totalHour = hour1 + hour2 + hour3;

totalCharge = charge1 + charge2 + charge3;

printf(" %.2f", totalHour);
printf(" %.2f", totalCharge);

return 0;

}

float calculateCharges(float hour, float charge) /* calculateCharge function */
{
if(hour <= 3.00){
charge = 2.00;
return charge;
}

else if(hour > 3.00){
 charge = 2.00 + 0.50 * (ceil(hour));
 return charge;
}

else if(hour = 24.00){
 charge = 10.00;
 return charge;
}

}

AltStyle によって変換されたページ (->オリジナル) /