### URGENT i have 2 hours to pass up my assignment

(Need to use sentinel-controlled while loop)

this is the work "students at a school volunteered to sell fresh baked cookies to raise funds to increase the number of computers in the computer lab. Each student reported the number of boxes he/she sold. Write a program that wil output the total number of boxes of cookies sold, the total revenue generated by selling the cookies and the saverage number of boxes sold by each student. The programmer do not know the exact number of volunteers involved, we assume that -1 that will mark the end of the data.
Assume the data input is in the following form: student's name followed by a space and the number of boxes sold by the student
 ``123456`` ``````std::string name ; int num_boxes ; while( std::cin >> name && name != "-1" && std::cin >> num_boxes && num_boxes != -1 ) { // ... }``````
What is this?
@MulStudent

 (Need to use sentinel-controlled while loop)

and
 What is this?

Last edited on
@whitenite1

so is that the only source code i need to type in c++ ?
My guess to what you mean by "sentinel-controlled while loop" is "loop until the user says to stop". If that is the case, you could make your loop conditional -1, but its much easier to use Boolean's (since these technically represent the values 0 and 1 respectively) once you understand the logic.

I think the code below is more what you're after:

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455`` ``````const int NAME = 10; // Max character counter for the student name. const int MAX = 100; // General maximum (for I/O and such). int main() { bool quit = false; // Loop conditional. char student[NAME]; // Name of student. // Num of students & boxes. int numof_students = 0, numof_boxes = 0, totalboxes = 0; // Price per box, total/avg revenue. int price = 0, revenue = 0, avg_sold; cout << " Set the price per box: "; cin >> price; cin.ignore(MAX, '\n'); do { cout <> numof_boxes; cin.ignore(MAX, '\n'); totalboxes += numof_boxes; // Sum the num of boxes... revenue += (price * numof_boxes); // ...and the revenue. char response; cout << " Enter another? (y/n):"; // Rinse & Repeat? cin >> response; cin.ignore(MAX, '\n'); response = tolower(response); if(response == 'n') quit = true; // Break from the loop. (quit = false otherwise) }while(!quit); avg_sold = revenue / numof_students; // Calculate the avg. cout << endl << endl << endl << " The total revenue is: " << revenue << endl << endl << " Average number of boxes sold: " << avg_sold << endl << endl; return 0; }``````

Hope that helps.
Last edited on
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687`` ``````#include #include #include using namespace std; struct student { string name; int boxesSold; float totalMade; }; float calcAverageBoxes(vector &, int); float calctotalRev(vector &, int); int calcTotalBoxes(vector &, int); int main() { vector info; info.push_back(student()); int size = info.size(); int count = 0; cout << "enter -1 to quit" << endl << endl; while(true) { size = info.size(); cout << "Enter in name of student " << size << " : "; getline(cin, info.at(count).name); if(info.at(count).name == "-1") { break; } cout << "How many boxes did student " << size << " sell: "; cin >> info.at(count).boxesSold; cout << "How many did student " << size << " make: "; cin >> info.at(count).totalMade; info.push_back(student()); count++; cin.ignore(); } for(int i = 0; i < size-1; i++) { cout << "Student: " << info.at(i).name << endl; cout << info.at(i).name << " sold boxes amount: " << info.at(i).boxesSold << endl; cout << info.at(i).name << " total money raised: " << info.at(i).totalMade << endl << endl; } cout << endl << endl; float averagebox = calcAverageBoxes(info, size); // average num of box sold by stuent int totalbox = calcTotalBoxes(info, size); // total box sold float rev = calctotalRev(info, size); // total rev //cout << "Average boxes sold by a student: " << averagebox << endl; //cout << "Total boxses sold: " << totalbox << endl; cout << "Total money raised: \$" << rev << endl; return 0; } float calcAverageBoxes(vector &info, int cnt) { float x = 0; for(int i = 0; i < cnt; i++) x = x+info.at(i).boxesSold; return x/info.size(); } float calctotalRev(vector &info, int cnt) { float x = 0; for(int i = 0; i < cnt; i++) x = x+info.at(i).totalMade; return x; } int calcTotalBoxes(vector &info, int cnt) { int x = 0; for(int i = 0; i < cnt; i++) x = x+info.at(i).boxesSold; return x; }``````

here is what i got. it's pretty messy, but if you can clean it up, good for u
Alright thank you very much!