write a c program to define a structure called a car. the member elements of the car structure are model(like bmw, ford...etc), production year (1999,2020,...), and lastly price. create an array of 10 cars. get input for all 10 cars from the user. then the program display complete information (model, year, price) of those cars only which are above 250000 in price or production date bigger than 2000.
#include <stdio.h>
#include <string.h>
#include <ctype.h>
struct car{
char model[20];
int productionYear;
float lastlyPrice;
};
int main(){
//create an array of 10 cars.
struct car cars[10];
int i;
//get input for all 10 cars from the user.
for (i=0;i<10;i++){
printf("Enter the model of the car: ");
gets(cars[i].model);
printf("Enter the production year of the car: ");
scanf("%d",&cars[i].productionYear);
printf("Enter the lastly price of the car: ");
scanf("%f",&cars[i].lastlyPrice);
fflush(stdin);
}
//the program display complete information (model, year, price)
//of those cars only which are above 250000 in price or production date bigger than 2000.
for (i=0;i<10;i++){
if(cars[i].productionYear>2000 || cars[i].lastlyPrice>250000){
printf("The model of the car: %s\n",cars[i].model);
printf("The production year of the car: %d\n",cars[i].productionYear);
printf("The lastly price of the car: %.2f\n\n",cars[i].lastlyPrice);
}
}
getchar();
getchar();
return 0;
}
Comments
Leave a comment