C Online Compiler
Example: Advanced Car Selector with Logical Operators in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Advanced Car Selector with Logical Operators #include <stdio.h> int main() { // Step 1: Declare variables for car criteria int price, fuel_efficiency, seating_capacity; char car_type[20]; // e.g., "Sedan", "SUV", "Hatchback" // Step 2: Get car details from user printf("Enter car price: $"); scanf("%d", &price); printf("Enter car fuel efficiency (MPG): "); scanf("%d", &fuel_efficiency); printf("Enter car seating capacity: "); scanf("%d", &seating_capacity); printf("Enter car type (e.g., Sedan, SUV, Hatchback): "); scanf("%19s", car_type); // Read string, limit to 19 chars + null terminator // Step 3: Apply conditions using logical operators printf("\nEvaluating car...\n"); // Condition for a family SUV if (price <= 40000 && fuel_efficiency >= 20 && seating_capacity >= 5 && (strcmp(car_type, "SUV") == 0 || strcmp(car_type, "Minivan") == 0)) { printf("This car is suitable for a family SUV/Minivan!\n"); } // Condition for an efficient city car else if (price <= 25000 && fuel_efficiency >= 35 && seating_capacity <= 5 && (strcmp(car_type, "Sedan") == 0 || strcmp(car_type, "Hatchback") == 0)) { printf("This car is ideal for city driving and efficiency!\n"); } // Condition for a high-performance/luxury car (less focus on efficiency, more on price/type) else if (price > 40000 && fuel_efficiency >= 15 && seating_capacity >= 2 && (strcmp(car_type, "Sports") == 0 || strcmp(car_type, "Luxury") == 0)) { printf("This car is a high-performance or luxury option.\n"); } else { printf("This car does not fit any specific categorized criteria.\n"); } return 0; }
Output
Clear
ADVERTISEMENTS