Question: Assume that the data is provided in a file called Ch 5 _ Ex 1 8 Data.txt and the first line in the file specifies

Assume that the data is provided in a file called Ch5_Ex18Data.txt and the first line in the file specifies the cost of one box.
Modify the program (in main.cpp) so that it uses an EOF-controlled loop to process the data from the text file.
#include
#include
#include
using namespace std;
const string SENTINEL ="-1";
int main()
{
string name;
int numOfVolunteers;
int numOfBoxesSold;
int totalNumOfBoxesSold;
double costOfOneBox;
cout << fixed << showpoint << setprecision(2);
cout << "Line 14: Enter each volunteer's name and "
<< "the number of boxes "<< endl
<<" sold by each volunteer, ending "
<< "with -1: "<< endl;
totalNumOfBoxesSold =0;
numOfVolunteers =0;
cin >> name;
while (name != SENTINEL)
{
cin >> numOfBoxesSold;
totalNumOfBoxesSold = totalNumOfBoxesSold
+ numOfBoxesSold;
numOfVolunteers++;
cin >> name;
}
cout << endl;
cout << "Line 26: The total number of boxes sold: "
<< totalNumOfBoxesSold << endl;
cout << "Line 27: Enter the cost of one box: ";
cin >> costOfOneBox;
cout << endl;
cout << "Line 30: The total money made by selling "
<< "cookies: $"
<< totalNumOfBoxesSold * costOfOneBox << endl;
if (numOfVolunteers !=0)
cout << "Line 32: The average number of "
<< "boxes sold by each volunteer: "
<< totalNumOfBoxesSold / numOfVolunteers
<< endl;
else
cout << "Line 34: No input." << endl;
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!