#include <iostream>
using namespace std;
int main() {
int numberOfStudents = 5;
int *numberOfBoxesSold = new int [numberOfStudents];
float priceOfLoafOfBread;
//getting initial data
cout << "Enter the price of a loaf of bread: ";
cin >> priceOfLoafOfBread;
cout << endl;
for (int i = 0; i < numberOfStudents; i++) {
cout << "The number of boxes student " << i << " sold: ";
cin >> numberOfBoxesSold[i];
}
cout << endl;
//the total number of loaves of bread sold
int totalLoavesSold = 0;
for (int i = 0; i < numberOfStudents; i++) {
totalLoavesSold += numberOfBoxesSold[i];
}
cout << "The total number of loaves of bread sold: " << totalLoavesSold << endl;
//the total revenue
float totalRevenue = 0.0;
for (int i = 0; i < numberOfStudents; i++) {
totalRevenue += numberOfBoxesSold[i] * priceOfLoafOfBread;
}
cout << "The total revenue: " << totalRevenue << endl;
//average number of loaves of bread sold by each student
float averageLoavesOfStudent = totalLoavesSold / numberOfStudents;
cout << "The average number of loaves of bread sold by each student: " << averageLoavesOfStudent;
return 0;
}
Comments
Leave a comment