#I might need a little help with this assignment

7 messages · Page 1 of 1 (latest)

whole moth
#

#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;

}

inner quailBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

whole moth
#

I have an assignment for my uni class and it wants us to do the following:
Upon running the program, display a welcome message to the user. The program displays gas prices for different types of gas.
Ask the user for their name and county.
If their answers for the county are “Miami Dade” or “Palm Beach”, please continue to the next step. Otherwise, display “The app only covers Miami Dade or Palm Beach counties.”
Ask if they would like to retype the county name. Repeat if the answer is “YES”. Otherwise, end the program.
For Miami Dade: Display prices for regular, midgrade, premium and diesel fuel. You may come up with values for each of those four categories.
For Palm Beach: Display prices for the four categories written for Miami Dade. Add 0.20 to the price for each of the categories.
Ask the user how many gallons they need for their vehicle?
Calculate and display the total amount based on user responses (county, number of gallons, etc).
I was able to write a code that was just fine for finding the gas price given how much you needed but it did not differentiate between different kinds of gas, which is what this code is trying to do, and it is NOT working properly.

#

Replit just spits this out on me but i have not tried doing it in vscode

#

Also, is replit ghostwrite ai worth shoveling 20 dollars out for it?

whole moth
#

I figured out the error and modified the code a little bit, I think I figured it out myself lol

#

!solved