-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrainfall_amount.c
132 lines (122 loc) · 4.02 KB
/
rainfall_amount.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include<stdio.h>
#include<conio.h>
#include <stdlib.h>
#include<string.h>
struct countries
{
int population;
int rainfall_a;
char name[20];
float area;
}; ///Country structure type
int displayAllCountriesinfoReverse(struct countries country[],int j,int n);
int searchACountry(struct countries country[],int j,int n);
int takeOneCountryInfoFromKeyboard(struct countries country[],int j);
int main()
{
int i,j,n=0;
int rainfall_amount;
char ch; ///ch=r/s/t/q
struct countries country[100];
printf("#Enter 'r' to take information of all the Countries.\n");
printf("\n#Enter 's' to search a Country by rainfall amount.\n");
printf("\n# Enter 't' to display the information of all the Countries in reverse index order.\n");
printf("\n#Enter 'q' to quit/exit the menu system.\n");
printf("\n\n==========Enter Your Choice : ");
fflush(stdin);
scanf("%c", &ch);
switch(ch)
{
case 'r' :
takeOneCountryInfoFromKeyboard(country,i);
i++;
n++;
break;
case 's' :
printf("No rainfall amount information is found. Please populate country information first.\n");
break;
case 't' :
printf("No rainfall amount information is found. Please populate country information first.\n");
break;
case 'q' :
printf("Exit the menu system..");
break;
default :
printf("Invalid Input\n");
}
while(ch!='q')
{
printf("\n\n==========Enter Your Choice : ");
fflush(stdin);
scanf("%c", &ch);
switch(ch)
{
case 'r' :
takeOneCountryInfoFromKeyboard(country,i);
i++;
n++;
break;
case 's':
searchACountry(country,i,n);
break;
case 't' :
displayAllCountriesinfoReverse(country,j,n);
break;
case 'q' :
printf("Exit the menu system..");
break;
default :
printf("Invalid Input");
break;
}
}
}
int searchACountry(struct countries country[],int j,int n)
{
int amount;
printf("==========Enter Rainfall Amount to Search :");
scanf("%d", &amount);
for (j = 0; j < n; j++)
{
if (country[j].rainfall_a == amount)
{
printf("\n");
printf("\n=====Name of The Country : %s\n",country[j].name);
printf("=====Population of %s : %d\n",country[j].name,country[j].population);
printf("=====Area of %s : %f\n",country[j].name,country[j].area);
printf("=====Rainfall Amount of %s : %d mm\n",country[j].name,country[j].rainfall_a);
printf("\n");
}
else if(country[j].rainfall_a != amount)
{
printf("%dmm Not Found for other countries\n",amount);
}
}
}
int displayAllCountriesinfoReverse(struct countries country[],int j,int n)
{
printf("\n");
printf("==========The Rainfall Amounts in Reverse Order : ");
printf("\n\n");
printf("COUNTRY NAME - COUNTRY POPULATION - COUNTRY AREA - RAINFALL AMOUNT\n");
for(j=n-1;j>=0;j--)
{
printf("%-15s",country[j].name);
printf("%-21d",country[j].population);
printf("%-15f",country[j].area);
printf("%d",country[j].rainfall_a);
printf("\n");
}
}
int takeOneCountryInfoFromKeyboard(struct countries country[],int j)
{
printf("\n\nEnter the Name of Country :");
fflush(stdin);
gets(country[j].name);
printf("\nEnter the Population of Country in crore :");
scanf("%d",&country[j].population);
printf("\nEnter the Area of Country in sq.km :");
scanf("%f",&country[j].area);
printf("\nEnter the number of rainfall amount in mm :");
scanf("%d",&country[j].rainfall_a); ///number of rainfall amount
}