-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathex3.c
40 lines (32 loc) · 1005 Bytes
/
ex3.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
/*
* 3. Program 6.2 permits only 20 responses to be entered. Modify that program
* so that any number of responses can be entered. So that the user does not
* have to count the number of responses in the list, set up the program so
* that the value 999 can be keyed in by the user to indicate that the last
* response has been entered. (Hint: You can use the break statement here if
* you want to exit your loop.)
*
* By Faisal Saadatmand
*/
#include <stdio.h>
int main(void)
{
int i, ratingCounters[11], response;
for (i = 0; i < 11; ++i)
ratingCounters[i] = 0;
printf("Enter your responses\n");
for (i = 1; ; ++i) {
scanf("%i", &response );
if (response == 999)
break;
if (response < 1 || response > 10)
printf("Invalid response: %i\n", response);
else
++ratingCounters[response];
}
printf("\n\nRating Number of Responses\n");
printf("------- -----------------------\n");
for (i = 0; i < 11; ++i)
printf("%4i%14i\n", i, ratingCounters[i]);
return 0;
}