C Online Compiler
Example: Budget-Based Car Selector in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Budget-Based Car Selector #include <stdio.h> int main() { // Step 1: Declare a variable to store the user's budget int budget; // Step 2: Prompt the user for their budget printf("Enter your maximum budget for a car (in USD): "); scanf("%d", &budget); // Step 3: Use if-else if-else to suggest a car based on budget if (budget < 10000) { printf("Given your budget of $%d, a Used Compact or Small Hatchback might be suitable.\n", budget); printf("Consider models like an older Honda Fit or Toyota Yaris.\n"); } else if (budget >= 10000 && budget < 25000) { printf("Given your budget of $%d, a New Compact Sedan or Mid-Size Hatchback is a good option.\n", budget); printf("Look for models such as a Honda Civic, Toyota Corolla, or Mazda 3.\n"); } else if (budget >= 25000 && budget < 40000) { printf("Given your budget of $%d, you can consider a Mid-Size Sedan, Small SUV, or Entry-Luxury Sedan.\n", budget); printf("Explore options like a Toyota Camry, Honda CR-V, or BMW 3 Series (used/entry).\n"); } else { // budget >= 40000 printf("Given your budget of $%d, you have a wide range of choices including Luxury Sedans, Premium SUVs, or Sports Cars.\n", budget); printf("Consider models such as a Mercedes-Benz C-Class, Audi Q5, or Ford Mustang.\n"); } return 0; }
Output
Clear
ADVERTISEMENTS