# Untitled

unknown
plain_text
a year ago
1.5 kB
1
Indexable
Never
```#include <stdio.h>
#include <math.h>

float calculateCharges (float x) {
if(x <= 3) {
return 2.00;
} else {
float result;
result = (x - 3) / 2;
result += 2;
return result;
}
}
int main() {
float x1, x2, x3, y1, y2, y3, totalHours, totalCharges;

printf("Welcome to the Parking Charges calculator!\n");

//  car 1
here1:
printf("Please enter the parking hours of car 1: ");
scanf("%f", &x1);
if(x1 <= 0){
printf("Please enter a number greater than 0!\n");
goto here1;
}
y1 = calculateCharges(x1);

//  car 2:
here2:
printf("Please enter the parking hours of car 2: ");
scanf("%f", &x2);
if(x2 <= 0){
printf("Please enter a number greater than 0!\n");
goto here2;
}
y2 = calculateCharges(x2);

//  car 3:
here3:
printf("Please enter the parking hours of car 3: ");
scanf("%f", &x3);
if(x3 <= 0){
printf("Please enter a number greater than 0!\n");
goto here3;
}
y3 = calculateCharges(x3);

//  total number of hours and charges:
totalHours = x1 + x2 + x3;
totalCharges = y1 + y2 + y3;

//  creating the table

int columns, rows = 1;

printf("%s%12s%13s\n", "Car", "Hours", "charge");
printf("%d%13.2f%13.2f\n", 1, x1, y1);
printf("%d%13.2f%13.2f\n", 2, x2, y2);
printf("%d%13.2f%13.2f\n", 3, x3, y3);
printf("%s%10.2f%12.2f\n", "TOTAL", totalHours, totalCharges);

}```