I am trying to write a program in C that would be used by a car rental company. This program finds the subtotal, tax amount(6%) and finally the total. The user enters in how many days the car was rented and how many miles were driven.

The total is based on this logic. The cars are rented for 15.00 per day plus .40 cents per mile if the car is driven less then 200 miles. If the car is driven more then 200 miles, the rate per mile is lowered to .35 cents per mile.

I know how to get the input from the user with printf and scanf but I am struggling with what to do next. I have to use a if...else statement. I don't have a firm grasp on C code yet.

bbbb

To calculate the subtotal, tax amount, and total for a car rental company program in C, you can follow these steps:

1. Retrieve the input from the user: Prompt the user to enter the number of days the car was rented and the number of miles driven. Use the `scanf` function to store the values in variables.

2. Calculate the subtotal: Multiply the number of days rented by the daily rate of $15.00. Use the following formula:
```
subtotal = days_rented * 15.00
```

3. Determine the mileage rate: Use an if...else statement to check if the miles driven is less than 200. If true, set the rate per mile to $0.40; otherwise, set it to $0.35. For example:
```c
if (miles_driven < 200) {
rate_per_mile = 0.40;
} else {
rate_per_mile = 0.35;
}
```

4. Calculate the mileage cost: Multiply the number of miles driven by the rate per mile. Use the following formula:
```
mileage_cost = miles_driven * rate_per_mile
```

5. Calculate the tax amount: Multiply the subtotal by the tax rate of 6%. Use the following formula:
```
tax_amount = subtotal * 0.06
```

6. Calculate the total: Add the subtotal, mileage cost, and tax amount to get the total cost. Use the following formula:
```
total = subtotal + mileage_cost + tax_amount
```

7. Display the results: Use the `printf` function to output the subtotal, mileage cost, tax amount, and total to the user.

Here's a sample code snippet that incorporates these steps:

```c
#include <stdio.h>

int main() {
int days_rented, miles_driven;
double subtotal, rate_per_mile, mileage_cost, tax_amount, total;

printf("Enter number of days rented: ");
scanf("%d", &days_rented);

printf("Enter number of miles driven: ");
scanf("%d", &miles_driven);

subtotal = days_rented * 15.00;

if (miles_driven < 200) {
rate_per_mile = 0.40;
} else {
rate_per_mile = 0.35;
}

mileage_cost = miles_driven * rate_per_mile;

tax_amount = subtotal * 0.06;

total = subtotal + mileage_cost + tax_amount;

printf("Subtotal: $%.2f\n", subtotal);
printf("Mileage Cost: $%.2f\n", mileage_cost);
printf("Tax Amount: $%.2f\n", tax_amount);
printf("Total: $%.2f\n", total);

return 0;
}
```

This code snippet takes the user input, calculates the necessary values based on the logic provided, and then displays the results to the user.