Question

In: Computer Science

ASSIGNMENT: Write a program to keep track of the total number of bugs collected in a...

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

Solutions

Expert Solution

#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;
}


Related Solutions

In this assignment, the program will keep track of the amount of rainfall for a 12-month...
In this assignment, the program will keep track of the amount of rainfall for a 12-month period. The data must be stored in an array of 12 doubles, each element of the array corresponds to one of the months. The program should make use of a second array of 12 strings, which will have the names of the months. These two arrays will be working in parallel. The array holding the month names will be initialized when the array is...
Write a c++ program for the Sales Department to keep track of the monthly sales of...
Write a c++ program for the Sales Department to keep track of the monthly sales of its salespersons. The program shall perform the following tasks: Create a base class “Employees” with a protected variable “phone_no” Create a derived class “Sales” from the base class “Employees” with two public variables “emp_no” and “emp_name” Create a second level of derived class “Salesperson” from the derived class “Sales” with two public variables “location” and “monthly_sales” Create a function “employee_details” under the class “Salesperson”...
Overview In this assignment, you will write a program to track monthly sales data for a...
Overview In this assignment, you will write a program to track monthly sales data for a small company. Input Input for this program will come from two different disk files. Your program will read from these files by explicitly opening them. The seller file (sellers.txt) consists of an unknown number of records, each representing one sale. Records consist of a last name, a first name, a seller ID, and a sales total. So, for example, the first few records in...
Write a Java program that lets the user keep track of their homemade salsa sales. Use...
Write a Java program that lets the user keep track of their homemade salsa sales. Use 5-element arrays to track the following. The salsa names mild, medium, sweet, hot, and zesty. The number of each type sold. The price of each type of salsa. Show gross amount of money made (before tax). Calculate how much the user owes in sales tax (6% of the amount made). Then display the net profit (after subtracting the tax).
USING PYTHON ONLY Write a gradebook program that lets a teacher keep track of test averages...
USING PYTHON ONLY Write a gradebook program that lets a teacher keep track of test averages for his or her students. Your program should begin by asking the teacher for a number of students in their class as well as the total # of tests that will be given to the class. Validate this information to ensure that the numbers entered are positive. Next, prompt the teacher to enter in scores for each student. Ensure that the values entered are...
Write a C++ program for Euclids Algorithm that keeps track of the number of iterations (%...
Write a C++ program for Euclids Algorithm that keeps track of the number of iterations (% & loop) 1. Euclid’s Algorithm An alternative of the Euclidean algorithm for finding greatest common divisors (GCD) is repeatedly performing the modulo operation on two numbers until the remainder is 0. Here is the pseudocode for find the GCD of two positive numbers a and b using the Euclidean algorithm :while b ≠ 0 temp = b b = a mod t a =...
Write a class to keep track of a balance in a bank account with a varying...
Write a class to keep track of a balance in a bank account with a varying annual interest rate. The constructor will set both the balance and the interest rate to some initial values (with defaults of zero). The class should have member functions to change or retrieve the current balance or interest rate. There should also be functions to make a deposit (add to the balance) or withdrawal (subtract from the balance). You should not allow more money to...
Write a class to keep track of a balance in a bank account with a varying...
Write a class to keep track of a balance in a bank account with a varying annual interest rate. The constructor will set both the balance and the interest rate to some initial values (with defaults of zero). The class should have member functions to change or retrieve the current balance or interest rate. There should also be functions to make a deposit (add to the balance) or withdrawal (subtract from the balance). You should not allow more money to...
In C++ For this assignment, you will write a program to count the number of times...
In C++ For this assignment, you will write a program to count the number of times the words in an input text file occur. The WordCount Structure Define a C++ struct called WordCount that contains the following data members: An array of 31 characters named word An integer named count Functions Write the following functions: int main(int argc, char* argv[]) This function should declare an array of 200 WordCount objects and an integer numWords to track the number of array...
A bakery does not keep track of the number of chocolate chips they put in their cookies.
  A bakery does not keep track of the number of chocolate chips they put in their cookies. The number of chocolate chips is normally distributed with mean µ and variance σ2 = 25, where µ is unknown. A customer buys a dozen of these cookies, and obtains the simple random sample 31, 23, 42, 44, 28, 34, 19, 29, 30, 25, 28, 27 (a) Compute a 95% confidence interval for µ. (b) Compute 90% and 99% confidence intervals for...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT