Question #90723

Students at a local middle school volunteered to sell fresh baked cookies to raise funds to increase the number of computers for the computer lab. Each student reported the number of boxes he/she sold.

Write a program that will ask as input the number of volunteers, the name of the volunteer, and the number of boxes sold by the volunteer. the the program produces as output the total number of boxes of cookies sold, the total revenue generated by selling the cookies, and the average number of boxes sold by each student

Expert's answer

#include <iostream>
using namespace std;

int main() {
    cout << "How many volunteers?\n";
    int vol;
    cin >> vol;

    cout << "What is the price of one box?\n";
    int cost;
    cin >> cost;

    int total = 0;

    for (int i = 1; i <= vol; i++) {
        cout << "Enter name of volunteer " << i << endl;
        string name; //no need to store
        cin >> name;
        cout << "Enter number of boxes sold:\n";
        int boxes;
        cin >> boxes;

        total += boxes;
    }
    cout << "Total number of boxes of cookies sold: " << total << endl;
    cout << "Total revenue generated by selling the cookies: $" << cost * total << endl;
    cout << "Average number of boxes sold by each student: " << (float)total / vol << endl;
}
LATEST TUTORIALS
APPROVED BY CLIENTS