Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

write a c program for car rental system

+5 votes
asked Aug 23, 2019 by anonymous

1 Answer

0 votes
answered Mar 28, 2025 by Tanishka Pandey (210 points)
#include <stdio.h>

struct Car {
    char name[20];
    int id;
    float price;
};

int main() {
    struct Car cars[] = {
        {"Toyota", 1, 50.0},
        {"Honda", 2, 60.0},
        {"Ford", 3, 55.0}
    };
    int choice, days;
    
    printf("Available cars:\n");
    for (int i = 0; i < 3; i++) {
        printf("%d. %s - $%.2f per day\n", cars[i].id, cars[i].name, cars[i].price);
    }
    
    printf("Enter car ID to rent: ");
    scanf("%d", &choice);
    
    printf("Enter number of days: ");
    scanf("%d", &days);
    
    if (choice >= 1 && choice <= 3) {
        float total = cars[choice - 1].price * days;
        printf("Total cost for renting %s for %d days: $%.2f\n", cars[choice - 1].name, days, total);
    } else {
        printf("Invalid car selection.\n");
    }
    
    return 0;
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...