Answer to Question #120246 in C++ for ernest

Question #120246
Learners at a local basic school volunteered to sell fresh baked bread to raise funds to
increase the number of computers for their computer lab. Each student reported the number
of loaves of bread he/she sold. Write a C programme that will output the total number of
loaves of bread sold, the total revenue generated by selling the bread, and the average
number of loaves of bread sold by each student. The input data is provided in the following
form: studentIndexNo numOfBoxesSold
1
Expert's answer
2020-06-05T05:50:08-0400
#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;

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS