In: Computer Science
ASSIGNMENT:
Write a program to keep track of the total number of bugs collected in a 7 day period. Ask the user for the number of bugs collected on each day, and using an accumulator, keep a running total of the number of bugs collected. Display the total number of bugs collected, the count of the number of days, and the average number of bugs collected every day.
Create a constant for the number of days the bugs are being collected, and use that number throughout the program. Using a decision, either display "bug" or "bugs" as appropriate.
There is no validation.
Example Run #1:
(bold type is what is entered by the user)
How many bugs were collected on day #1? 5
How many bugs were collected on day #2? 2
How many bugs were collected on day #3? 3
How many bugs were collected on day #4? 6
How many bugs were collected on day #5? 1
How many bugs were collected on day #6? 4
How many bugs were collected on day #7? 2
In the 7 day period, the total number of bugs collected was xx
bugs.
The count is: x days
The average is: x.xx bugs per day
Example Run #2:
How many bugs were collected on day #1? 1
How many bugs were collected on day #2? 0
How many bugs were collected on day #3? 0
How many bugs were collected on day #4? 0
How many bugs were collected on day #5? 0
How many bugs were collected on day #6? 0
How many bugs were collected on day #7? 0
In the 7 day period, the total number of bugs collected was x
bug.
The count is: x days
The average is: x.xx bugs per day
The example runs show EXACTLY how your program input and output will look.
C programming no floats
#include <stdio.h> #define NUM_DAYS 7 int main() { int i, total = 0, count; for (i = 0; i < NUM_DAYS; ++i) { printf("How many bugs were collected on day #%d? ", i + 1); scanf("%d", &count); total += count; } if (total != 1) { printf("In the 7 day period, the total number of bugs collected was %d bugs.\n", total); } else { printf("In the 7 day period, the total number of bugs collected was %d bug.\n", total); } printf("The count is: %d days\n", NUM_DAYS); printf("The average is: %.2lf bugs per day\n", total / (double) NUM_DAYS); return 0; }