How can we return an array from a function i have no idea how to do this??? the are three cars and each is parked in a parking area for maximum 24 hours we have to find the cost for each car by making a function which wil evaluate the cost..??
#include <stdio.h>
#include <math.h>
#include <conio.h>
int calculateCharges(float hours[]);
int main() {
float hours[3];
int i;
for (i = 0; i <= 2; i++) {
printf("Enter the hours you parked for car : %d\n", i + 1);
scanf_s("%f", &hours[i]);
}
hours[i] = calculateCharges(hours[]);
printf("%-10s%-10s%-10s\n", "Cars", "Hours", "Charge");
for (i = 0;i <= 2;i++) {
printf("%-10d%-10.2f%-10.2f\n", i + 1, hours[i], calculateCharges(hours));
}
_getch();
return 0;
}
int calculateCharges(float hours[]) {
float cost[3];
int i;
for (i = 0; i <= 2; i++) {
if (hours[i] <= 3) { //if car parked for 3 or less hours it cost 2$
cost[i] = 2;
}
else if (hours[i] > 3 && hours[i] < 24) { //if car parked for more than 3 or less then 24 hours it cost 0.5$for each extra hour$
cost[i] = 2 + ((hours[i] - 3) / 2);
}
else if (hours[i] == 24) { //if hours = 24 hours 10$
cost[i] = 10;
}
else {
cost[i] = 0; //else its an error value zero cost
}
return cost[i];
}
}