Code:
#include <stdio.h>
void swapValues();
int a, b;
float tempcharge, tempcar, temphours, charges[], hours[];
float calculateTimeSpent(float a, float b, float c, float d){
float timeSpent, x;
if (d < b){
c--;
d +=60;
}
timeSpent = (c - a) + (d - b)/60;
return timeSpent;
}
float timeEntryCars(){
int hhEntry, mmEntry, hhExit, mmExit, hour, minute;
printf("Enter time of entry: ");
scanf("%d:%d", &hhEntry, &mmEntry);
printf("Enter time of exit: ");
scanf("%d:%d", &hhExit, &mmExit);
return calculateTimeSpent(hhEntry, mmEntry, hhExit, mmExit);
}
float calculateCharges(float x){
int ans = 45;
int remainder, quotient, y;
if (x<=2) ans = 45;
else{
x -=2;
y = x*100;
remainder = y%50;
quotient = y/50;
if (remainder >= 0) ans = ans + (quotient*10);
else ans = ans + ((quotient+1)*10);
}
return ans;
}
int main(){
int Cars;
printf("input number of Cars: ");
scanf("%d", &Cars);
float car[Cars];
int charge;
int i, j;
float totalHours = 0;
int totalCharge = 0;
void swapValues(){
for(a=0;a<=Cars-1; a++) {
for(j = a+1;b<=Cars; b++) {
if(charges[a] > charges[b]) {
tempcar = car[a]; //save the values at index i
tempcharge = charges[a];
temphours= hours[a];
car[a] = car[b]; //swap car number and all values at index i
charges[a] = charges[b]; //swap charges
hours[a] = hours[b]; //swap hours used
car[b] = tempcar; //reassign the temp values from i, down to index j
charges[b] = tempcharge;
hours[b] = temphours;
}
}
}
}
for (i = 0; i<=Cars-1; i++) {
printf("For car %d>> \n", i + 1);
car [i] = timeEntryCars();
}
printf("Car \t Hours \t Charge\n");
swapValues();
for (j = 0; j<=Cars-1; j++) {
charge = calculateCharges(car[j]);
printf("%d\t %.2f\t %d\n", j + 1, car[j], charge);
totalHours +=car[j];
totalCharge +=charge;
}
printf("TOTAL\t %.2f\t %d\n", totalHours, totalCharge);
return 0;
}
still not working properly. :'(