Would need help for array project !

Hey guys ! I would love to get some help for my following project , i am stuck on how do i go about displaying the amount of days with no rain, meaning days with 0.0MM of rainfall in the month of january when the user selects 'I' or 'i'? My code uses arrays stored in an external source to store data of the rainfall as shown below , the first code.

Also last but not least how do i go about allowing the user to change the data of the arrays and print them out ?

Thanks in advance for the help ! Appreciate them a lot :)
1
2
3
4
5
float rainfallJan[30]={0.0,0.0,0.0,0.0,18.4,31.2,0.0,0.0,2.0,5.6,18.2,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};

float rainfallFeb[27]={0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.2,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};

float rainfallMar[30]={0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,52.6,5.4,0.4,0.0,2.0,5.2,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.4,0.0};

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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
 #include <stdio.h>
// Call in functions from external source files for usage in the main program 
extern float rainfallJan[];   
extern float rainfallFeb[]; 
extern float rainfallMar[];
extern void getPwd(char* pwd);	// function prototype to store password input
extern int chkPwd(char* pwd);  


void SystemLogin(void);
void rainfallMenu(void);

void main(void)
{
	char userinput;    
	int j;
	int month;
    float total;
	float totaldataJan;
	float totaldataFeb;
	float totaldataMar;
	float lowestAverage;
	float Totalaverage;
	float AverageJan;
    float AverageFeb;
    float AverageMar;
						
	float max;
	char systemPwd[]="601427";	// declare system password as global string variable
	SystemLogin(); // Call in function for logging into the system


         do 
		 {
		
			 rainfallMenu();//call function to display menu 
		     
			 userinput=getchar(); // Record user input with getchar() function
		    
			 fflush(stdin); //remove remaining input stream data

			    switch(userinput) // Start switch case 
					
				{

					case 'A': case 'a': 
				 
				    printf("The raifall data for January from day 1 down to day 31 respectively is :\n");
					totaldataJan=0;
					for ( j=0;j<31;j++ ) 
					{
						printf("   %.2f\n", rainfallJan[j]);  // To display rainfall data from external array
						totaldataJan = totaldataJan+rainfallJan[j]; // Calculate the total rainfall in the array data
					}
					printf("\n\n");
					printf("With the data , the total amount of rainfall in MM is %.2f\n", totaldataJan); 
			        printf("\n\n");
			        printf("\n\n");
					printf("\n\n");
					printf("View more rainfall data or quit from the following options :\n");
					printf("\n\n");

			     break;
				
					case 'B': case 'b':
					printf("The rainfall data for Febuary from day 1 down to day 28 respectively is:\n");
					totaldataFeb=0;
					for ( j=0; j<29; j++ )
					{
						printf("   %.2f\n", rainfallFeb[j]);  // To display rainfall data from external array
					    totaldataFeb = totaldataFeb+rainfallFeb[j]; // Calculate the total rainfall in the array data
					}
					printf("\n\n");
					printf("With the data , the total amount of rainfall in MM is %.2f\n", totaldataFeb);
			        printf("\n\n");
					printf("\n\n");
					printf("View more rainfall data or quit from the following options :\n");
					printf("\n\n");

				break;

					case 'C': case 'c':

					printf("The rainfall data for March from day 1 down to day 31 respectively is:\n");
					totaldataMar=0;
					for ( j=0; j<32; j++ )
					{
						printf("   %.2f\n", rainfallMar[j]);  // To display rainfall data from external array
					    totaldataMar = totaldataMar+rainfallMar[j]; // Calculate the total rainfall in the array data
					}
					printf("\n\n");
					printf("With the data , the total amount of rainfall in MM is %.2f\n", totaldataMar);
			        printf("\n\n");
					printf("\n\n");
					printf("View more rainfall data or quit from the following options :\n");
					printf("\n\n");

				break;

					case 'D': case 'd':
    
						  max = 0.0; 
						for(j=0;j<31;j++)
                            {
                                if (rainfallJan[j] > max) 
								{
                                  max = rainfallJan[j];
								}
						    }
						printf("\n\n");
						printf("The maximum rainfall for the month of January is %.2f\n", max);
						printf("\n\n");
						printf("View more rainfall data or quit from the following options :\n");
					    printf("\n\n");
						
				break;

					case 'E': case 'e':
						 
		                max = 0.0;
						for(j=0;j<28;j++)
                            {
                                if (rainfallFeb[j] > max)
								{
                                  max = rainfallFeb[j];
								}
						    }
						printf("\n\n");
						printf("The maximum rainfall for the month of February is %.2f\n", max);
						printf("\n\n");
						printf("View more rainfall data or quit from the following options :\n");
					    printf("\n\n");
				

				break;

					case 'F' : case 'f':

					    max = 0.0;
				       for(j=0;j<31;j++)
                            {
                                if (rainfallMar[j] > max)
								{
                                  max = rainfallMar[j];
								}
						    }
					    printf("\n\n");
						printf("The maximum rainfall for the month of March is %.2f\n", max);
						printf("\n\n");
						printf("View more rainfall data or quit from the following options :\n");
					    printf("\n\n");

				break;

					case 'G': case 'g':
				    AverageJan=(totaldataJan)/31;
					AverageFeb=(totaldataFeb)/28;
					AverageMar=(totaldataMar)/31;
					printf("The average rainfall of January is : %.2f\n", AverageJan);
					printf("The average rainfall of February is : %.2f\n", AverageFeb);
					printf("The average rainfall of March is : %.2f\n", AverageMar);
					printf("\n\n");
					printf("Thus the month with the lowest average rainfall is February , at 0.01 MM\n");
					printf("\n\n");
					printf("View more rainfall data or quit from the following options :\n");
					printf("\n\n");

				 break;

				     case 'H': case 'h':
						printf("The total rain for the month January is : %.2f\n", totaldataJan);
						printf("The total rain for the month February is : %.2f\n", totaldataFeb);
						printf("The total rain for the month March is : %.2f\n", totaldataMar);
						printf("According to the calculated datas , the month with the most rain is Januray\n");
						printf("\n\n");
					    printf("View more rainfall data or quit from the following options :\n");
					    printf("\n\n");

				 break;

					 case 'I': case 'i':
					
                                 break;

                    case 'Q': case 'q':
			       
					userinput='Q';
			    
				break;
		
		           default:
			
			        printf("Incorrect input please try again\n");
					

			        printf("\n\n");
					printf("\n\n");
					printf("Please choose from the following options again:\n");
					printf("\n\n");

					break;
		}
	}
	while ( userinput!='Q' );
}
Topic archived. No new replies allowed.