Write a Modular C Programming code for Finding the number and details of the Drink type, the least, expensive one
Display:
- The details of drinks purchased for more than Rs. 1000 worth
- The details of drinks purchased least and their price
Read the number of Drinks, read their information, and display the details of the students:
CODE:
#include<stdio.h> #include<string.h> struct shop { char type[30]; char name[30]; float price; char customer[30]; int units; }; struct shop s[100]; void read(struct shop s[100],int n); void display(struct shop s[100],int n); void purchase(struct shop s[100],int n); void softdrink(struct shop s[100],int n); main() { int n; printf("Enter number of people: "); scanf("%d",&n); if(n>0) { read(s,n); display(s,n); purchase(s,n); softdrink(s,n); } else { printf("Invalid Input\n"); } } void read(struct shop s[100],int n) { int i; printf("\nEnter the details of Drink: \n"); for(i=0;i<n;i++) { printf("\nEnter the Type(softdrink or hotdrinks): "); scanf("%s",&s[i].type); printf("Enter the Name of Drink: "); scanf("%s",&s[i].name); printf("Enter the Price: "); scanf("%f",&s[i].price); printf("Enter the Customer name:"); scanf("%s",&s[i].customer); printf("Enter the no_Of_times units took:"); scanf("%d",&s[i].units); printf("\n+++++++++++++++++++++++++++++++++++++++++++++++++\n"); } } void display(struct shop s[100],int n) { int i; printf("The details are:\n\n"); for(i=0;i<n;i++) { printf("Type=%s\tName=%s\tPrice=%f\tCustomer=%s\tUnits=%d\n",s[i].type,s[i].name,s[i].price,s[i].customer,s[i].units); } printf("\n+++++++++++++++++++++++++++++++++++++++++++++++++\n"); } void purchase(struct shop s[100],int n) { int i; float p; printf("\nThe details of cold drinks that have been purchased more than Rs.1000:\n"); for(i=0;i<n;i++) { p=s[i].price*s[i].units; if(p>1000) { printf("Price=%f\n",p); printf("Type=%s\tName=%s\tPrice=%f\tCustomer=%s\tUnits=%d\n",s[i].type,s[i].name,s[i].price,s[i].customer,s[i].units); } } printf("\n+++++++++++++++++++++++++++++++++++++++++++++++++\n"); } void softdrink(struct shop s[100],int n) { int i,k,p; float min; min=s[0].price; for(i=0;i<n;i++) { p=strcmp(s[i].type,"softdrink"); if(p==0) { if(s[i].price < min) { min=s[i].price; k=i; } } } printf("\nThe least price of soft drink=%f\n",min); printf("\nThe details of soft drink whose price/unit is least among all soft drinks:\n"); printf("\nType=%s\tName=%s\tPrice=%f\tCustomer=%s\tUnits=%d\n",s[k].type,s[k].name,s[k].price,s[k].customer,s[k].units); }
OUTPUT
Enter number of people: 5 Enter the details of Drink: Enter the Type(softdrink or hotdrinks): softdrink Enter the Name of Drink: coke Enter the Price: 250 Enter the Customer name:jin Enter the no_Of_times units took:23 +++++++++++++++++++++++++++++++++++++++++++++++++ Enter the Type(softdrink or hotdrinks): softdrink Enter the Name of Drink: redbull Enter the Price: 120 Enter the Customer name:sarp Enter the no_Of_times units took:3 +++++++++++++++++++++++++++++++++++++++++++++++++ Enter the Type(softdrink or hotdrinks): hotdrinks Enter the Name of Drink: tea Enter the Price: 15 Enter the Customer name:prat Enter the no_Of_times units took:250 +++++++++++++++++++++++++++++++++++++++++++++++++ Enter the Type(softdrink or hotdrinks): softdrink Enter the Name of Drink: coffee Enter the Price: 259 Enter the Customer name:anaa Enter the no_Of_times units took:6 +++++++++++++++++++++++++++++++++++++++++++++++++ Enter the Type(softdrink or hotdrinks): hotdrink Enter the Name of Drink: water Enter the Price: 20 Enter the Customer name:neer Enter the no_Of_times units took:420 +++++++++++++++++++++++++++++++++++++++++++++++++ The details are: Type=softdrink Name=coke Price=250.000000 Customer=jin Units=23 Type=softdrink Name=redbull Price=120.000000 Customer=sarp Units=3 Type=hotdrinks Name=tea Price=15.000000 Customer=prat Units=250 Type=softdrink Name=coffee Price=259.000000 Customer=anaa Units=6 Type=hotdrink Name=water Price=20.000000 Customer=neer Units=420 +++++++++++++++++++++++++++++++++++++++++++++++++ The details of cold drinks that have been purchased more than Rs.1000: Price=5750.000000 Type=softdrink Name=coke Price=250.000000 Customer=jin Units=23 Price=3750.000000 Type=hotdrinks Name=tea Price=15.000000 Customer=prat Units=250 Price=1554.000000 Type=softdrink Name=coffee Price=259.000000 Customer=anaa Units=6 Price=8400.000000 Type=hotdrink Name=water Price=20.000000 Customer=neer Units=420 +++++++++++++++++++++++++++++++++++++++++++++++++ The least price of soft drink=120.000000 The details of soft drink whose price/unit is least among all soft drinks: Type=softdrink Name=redbull Price=120.000000 Customer=sarp Units=3 Process returned 0 (0x0) execution time : 369.409 s Press any key to continue.
© Credits
Ananya Deshpande (1)
'H' div
Department of Computer Science
( ) — Number of Contributions!
Please find some more codes of 1D Arrays, 2D Arrays, Strings, Pointers, Data Structures, Files, Linked lists, and MISC on the below page:
Top 100+ C Programming codes – KLE Technological University