#include <stdio.h>
#include <string.h>
int main() {
char name[50];
char county[50];
char gas_type[20]; // Added a variable to store the gas type
char retry[4];
float regular_price_miami_dade = 3.00;
float midgrade_price_miami_dade = 3.50;
float premium_price_miami_dade = 4.00;
float diesel_price_miami_dade = 3.20;
float regular_price_palm_beach = regular_price_miami_dade + 0.20;
float midgrade_price_palm_beach = midgrade_price_miami_dade + 0.20;
float premium_price_palm_beach = premium_price_miami_dade + 0.20;
float diesel_price_palm_beach = diesel_price_miami_dade + 0.20;
float gallons;
float total_amount;
printf("Welcome to the Gas Price Calculator!\n");
printf("Please enter your name: ");
scanf("%s", name);
printf("Please enter your county without spaces, just like PalmBeach: ");
scanf("%s", county);
while (1) {
if (strcmp(county, "MiamiDade") == 0 || strcmp(county, "PalmBeach") == 0) {
if (strcmp(county, "MiamiDade") == 0) {
printf("Gas prices for Miami-Dade County:\n");
printf("Regular: $%.2f per gallon\n", regular_price_miami_dade);
printf("Midgrade: $%.2f per gallon\n", midgrade_price_miami_dade);
printf("Premium: $%.2f per gallon\n", premium_price_miami_dade);
printf("Diesel: $%.2f per gallon\n", diesel_price_miami_dade);
} else {
printf("Gas prices for Palm Beach County:\n");
printf("Regular: $%.2f per gallon\n", regular_price_palm_beach);
printf("Midgrade: $%.2f per gallon\n", midgrade_price_palm_beach);
printf("Premium: $%.2f per gallon\n", premium_price_palm_beach);
printf("Diesel: $%.2f per gallon\n", diesel_price_palm_beach);
}
// Ask for the gas type
printf("Enter the type of gas needed (Regular/Midgrade/Premium/Diesel): ");
scanf("%s", gas_type);
// Calculate the total amount based on the selected gas type
if (strcmp(gas_type, "Regular") == 0) {
total_amount = gallons * (strcmp(county, "MiamiDade") == 0 ? regular_price_miami_dade : regular_price_palm_beach);
} else if (strcmp(gas_type, "Midgrade") == 0) {
total_amount = gallons * (strcmp(county, "MiamiDade") == 0 ? midgrade_price_miami_dade : midgrade_price_palm_beach);
} else if (strcmp(gas_type, "Premium") == 0) {
total_amount = gallons * (strcmp(county, "MiamiDade") == 0 ? premium_price_miami_dade : premium_price_palm_beach);
} else if (strcmp(gas_type, "Diesel") == 0) {
total_amount = gallons * (strcmp(county, "MiamiDade") == 0 ? diesel_price_miami_dade : diesel_price_palm_beach);
} else {
printf("Invalid gas type. Please enter a valid gas type.\n");
continue;
}
printf("How many gallons do you need for your vehicle? ");
scanf("%f", &gallons);
printf("Total amount: $%.2f\n", total_amount);
break;
} else {
printf("The app only covers MiamiDade or PalmBeach counties.\n");
printf("Would you like to retype the county name? (YES/NO): ");
scanf("%s", retry);
if (strcmp(retry, "YES") != 0) {
break;
} else {
printf("Please enter your county: ");
scanf("%s", county);
}
}
}
return 0;
}