#include <stdio.h>
#include <string.h>
// Function to calculate car price based on input parameters
float calculateCarPrice(int year, const char *make, const char *model, const char *condition) {
// In a real-world scenario, you would fetch pricing information from a database or API
// For simplicity, we use a dummy value here
float basePrice = 10000.0; // Replace this with actual pricing information retrieval logic
float price;
// You can add more sophisticated logic to calculate price based on various factors
// For example, consider condition and adjust the price accordingly
if (strcmp(condition, "good") == 0) {
price = basePrice;
} else if (strcmp(condition, "fair") == 0) {
price = basePrice * 0.7;
} else if (strcmp(condition, "bad") == 0) {
price = basePrice * 0.4;
} else if (strcmp(condition, "totaled") == 0) {
price = basePrice * 0.1;
} else {
printf("Invalid condition entered.\n\n\n");
return -1.0; // Indicate an error
}
return price;
}
int main() {
int year;
char make[50], model[50], condition[20];
printf("Enter the year of the car: \n\n\n");
scanf("%d", &year);
printf("Enter the make of the car: \n\n\n");
scanf("%s", make);
printf("Enter the model of the car: \n\n\n");
scanf("%s", model);
printf("Enter the condition of the car (good, fair, bad, totaled): \n\n\n\n\n");
scanf("%s", condition);
// Calculate the car price using the provided function
float carPrice = calculateCarPrice(year, make, model, condition);
if (carPrice != -1.0) {
// Display the result
printf("Car Price: $%.2f\n", carPrice);
} else {
printf("Error in condition input.\n\n\n");
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: