C Online Compiler
Example: Multi-Criteria Car Selector in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Multi-Criteria Car Selector #include <stdio.h> int main() { // Step 1: Declare variables for various car criteria int budget; int fuel_choice; // 1: Petrol, 2: Diesel, 3: Electric int seating_choice; // 1: 2-3 seats, 2: 4-5 seats, 3: 6-7 seats // Step 2: Get user inputs printf("Welcome to the Multi-Criteria Car Selector!\n"); printf("Enter your maximum budget (in USD): "); scanf("%d", &budget); printf("\nChoose preferred fuel type:\n"); printf(" 1. Petrol\n"); printf(" 2. Diesel\n"); printf(" 3. Electric\n"); printf("Enter your choice (1-3): "); scanf("%d", &fuel_choice); printf("\nChoose preferred seating capacity:\n"); printf(" 1. 2-3 seats (e.g., Sports car, Mini compact)\n"); printf(" 2. 4-5 seats (e.g., Sedan, Hatchback, Small SUV)\n"); printf(" 3. 6-7 seats (e.g., MPV, Large SUV)\n"); printf("Enter your choice (1-3): "); scanf("%d", &seating_choice); // Step 3: Apply complex conditions to suggest a car printf("\nAnalyzing your preferences...\n"); if (budget < 15000) { if (seating_choice == 2 && fuel_choice == 1) { printf("Recommendation: Economical Hatchback/Sedan (e.g., Renault Kwid, Datsun Go).\n"); } else if (seating_choice == 1) { printf("Recommendation: Used Mini Compact Car (e.g., Smart Fortwo).\n"); } else { printf("Recommendation: Limited options in this budget for specific fuel/seating. Consider used.\n"); } } else if (budget >= 15000 && budget < 30000) { if (seating_choice == 2) { if (fuel_choice == 1) { printf("Recommendation: Mid-range Petrol Sedan/Hatchback (e.g., Hyundai i20, Honda City).\n"); } else if (fuel_choice == 2) { printf("Recommendation: Mid-range Diesel Sedan/Hatchback (e.g., Hyundai Verna Diesel).\n"); } else if (fuel_choice == 3) { printf("Recommendation: Entry-level Electric Vehicle (e.g., Tata Nexon EV, MG Comet EV).\n"); } else { printf("Recommendation: Explore petrol/diesel options in this segment.\n"); } } else if (seating_choice == 3) { printf("Recommendation: Entry-level MPV/SUV (e.g., Maruti Ertiga, Kia Carens - petrol/diesel).\n"); } else { printf("Recommendation: Consider mid-range options with 4-5 seats as main choice.\n"); } } else if (budget >= 30000 && budget < 50000) { if (seating_choice == 2) { if (fuel_choice == 1 || fuel_choice == 2) { printf("Recommendation: Premium Mid-size Sedan/SUV (e.g., Skoda Octavia, Hyundai Creta).\n"); } else if (fuel_choice == 3) { printf("Recommendation: Mid-range Electric Car (e.g., MG ZS EV, Mahindra XUV400).\n"); } } else if (seating_choice == 3) { if (fuel_choice == 1 || fuel_choice == 2) { printf("Recommendation: Large SUV/MPV (e.g., Toyota Innova, Mahindra XUV700).\n"); } else if (fuel_choice == 3) { printf("Recommendation: Larger Electric SUV (e.g., BYD Atto 3).\n"); } } else { printf("Recommendation: Wide range of premium options available.\n"); } } else { // budget >= 50000 printf("Recommendation: Luxury Segment. Options include premium sedans, high-end SUVs, or performance EVs.\n"); printf(" Consider brands like Mercedes-Benz, BMW, Audi, Tesla, Volvo.\n"); } return 0; }
Output
Clear
ADVERTISEMENTS