-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathP-77.c
61 lines (61 loc) · 1.22 KB
/
P-77.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//Smart bazaar, a subsidary of reliance, wants to store the following: product name, id and price. write a program in c to help reliance in storing the following details such that if they want to search a product via name or id, they should be able to get the details.
#include <stdio.h>
int main()
{
int ch,count=0;
char n[15];
long int d;
struct product
{
char name[15];
long int id;
float price;
};
struct product c[5]={"Tea",213421,50,"Coffee",715423,100,"Cadburry",213224,20,"Coke",215621,50,"Face Wash",657421,200};
printf("Enter the mode of search:\n");
printf("1. Name.\n");
printf("2. ID.\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
puts("Enter the name of the product:\n");
getchar();
gets(n);
for(int i=0;i<5;i++)
{
if((strcasecmp(c[i].name,n)==0))
{
printf("Name:%s\n",c[i].name);
printf("ID:%ld\n",c[i].id);
printf("Price:%f",c[i].price);
count++;
break;
}
}
if(count==0)
{
printf("WRONG CHOICE!");
}
break;
case 2:
printf("Enter the ID of the product:\n");
scanf("%ld",&d);
for(int i=0;i<5;i++)
{
if(c[i].id==d)
{
printf("Name:%s\n",c[i].name);
printf("ID:%ld\n",c[i].id);
printf("Price:%f",c[i].price);
count++;
break;
}
}
if(count==0)
{
printf("WRONG CHOICE!");
}
break;
}
}