Answer to Question #214051 in C for Almas

Question #214051

Mr. Pratheek wants to buy 10 items from the shop. He want to store the price of all the items. Mr. Pratheek want to list all the items which are less than a particular price. Help Mr. Pratheek to store the price of all ten items and list all the items less than a particular price


Requirements: 1: Read the price.


2: Compare the price with all price in Mr. Pratheek items


3: Display the item number whose value is less than the price.


1
Expert's answer
2021-07-06T09:33:08-0400
#include<stdio.h>




int main(){
	
	char itemNames[10][50];
	float prices[10];
	int i;
	float priceCompare;
	int number=0;
	for(i=0; i<10; i++){
		printf("Enter the name for item %d: ",(i+1));
		gets(itemNames[i]);
		printf("Enter the price for %s: ",itemNames[i]);
		scanf("%f",&prices[i]);
		fflush(stdin);
	}
	//Requirements: 1: Read the price.
	
	printf("Enter the price to compare with other prices: ");
	scanf("%f",&priceCompare);
	printf("The items whose prices is less than the particular price entered by  Mr. Pratheek are:\n");
	for(i=0; i<10; i++){
		//2: Compare the price with all price in Mr. Pratheek items
		if(prices[i]<priceCompare){
			printf("%s\n",itemNames[i]);
			number++;
		}
	}
	//3: Display the item number whose value is less than the price.
	printf("The number of item whose values are less than the price is: %d",number);


	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