Answer to Question #286626 in C for Stoic

Question #286626

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.



1
Expert's answer
2022-01-11T11:06:30-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS