ok so here is my program now
Code:
#include <stdio.h>
#include <math.h>
float calculateCharges(float);
const int NUMBER_OF_CARS= 8;
main()
{
int cars[NUMBER_OF_CARS]= {1,2,3,4,5,6,7,8};
float charges[NUMBER_OF_CARS];
float hours=0.0;
float totalHours= 0.0;
float totalCharges= 0.0;
int i;
for(i=0; i<NUMBER_OF_CARS; i++)
{
printf("Enter the hours for car %d:\n", cars[NUMBER_OF_CARS]);
scanf("%.1f",&hours);
totalHours = totalHours + hours;
charges[i] = calculateCharges(hours);
totalCharges = totalCharges + charges[i];
printf("\n");
printf("Car\t\t\Hours\t\t\Charge\n");
printf("%d\t\t\%.1f\t\t\%.2\n", cars[i], hours, charges[i]);
}
printf("TOTAL\t\t\%.1f\t\t\%.2f", totalHours, totalCharges);
float calculateCharges(float hours)
{
const float MINIMUM_CHARGE = 2.0;
const float MAXIMUM_CHARGE = 10.00;
/* the garage charges 2.00 for any amount of time up to 3 hours */
if (h<=3)
return MINIMUM_CHARGE;
/* determine how many hours past 3 hours */
h = h - 3;
/* 0.50 for each hour (or part of an hour) past 3 hours */
float additionalAmount = ceil(h) * 0.50;
float charge = MINIMUM_CHARGE + additionalAmount;
if (charge > MAXIMUM_CHARGE)
return MAXIMUM_CHARGE;
else
return charge;
}
and these are my error messages and ive tried fixing them but nothing changes
pgm39prog6.c:25:10: warning: unknown escape sequence '\H'
pgm39prog6.c:25:10: warning: unknown escape sequence '\C'
pgm39prog6.c:30: error: `totalHours' was not declared in this scope
pgm39prog6.c:30: error: `totalCharges' was not declared in this scope
pgm39prog6.c:30: error: ISO C++ forbids declaration of `printf' with no type
pgm39prog6.c:30: error: `int printf' redeclared as different kind of symbol
/usr/include/iso/stdio_iso.h:179: error: previous declaration of `int
printf(const char*, ...)'
pgm39prog6.c:30: error: initializer list being treated as compound expression
pgm39prog6.c: In function `float calculateCharges(float)':
pgm39prog6.c:38: error: `h' undeclared (first use this function)
pgm39prog6.c:38: error: (Each undeclared identifier is reported only once for
each function it appears in.)