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).
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...
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...
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...
You will design a program to keep track of a restaurants waitlist using a queue implemented...
You will design a program to keep track of a restaurants waitlist using a queue implemented with a linked list. Make sure to read pages 1215-1217 and 1227-1251 1. Create a class named waitList that can store a name and number of guests. Use constructors to automatically initialize the member variables. 2. Add the following operations to your program: a. Return the first person in the queue b. Return the last person in the queue c. Add a person to...
Problem statement: You are tasked with writing a simple program that will keep track of items...
Problem statement: You are tasked with writing a simple program that will keep track of items sold by a retail store. We need to keep track of the stock (or number of specific products available for sale). Requirements: The program will now be broken up into methods and store all the inventory in an ArrayList object. The program will be able to run a report for all inventory details as well as a report for items that are low in...
You are going to create a console based program to keep track of a small business...
You are going to create a console based program to keep track of a small business that sells Doodads. First you will need to create a class Doodad that keeps track of two integers and two Strings. Next, create a constructor for the Doodad. Next, add getters and setters for each of the fields (two integers and two Strings). You need to use Doodad.java (see the starter code) Inside your main method ask the user to read in the two...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT