Tutorial#26 - Programming Example-3 | Counter Control Loop

Programming Example-3 | Counter Control Loop

Counter Control Loop Program Example:

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. We will write a program that will 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. The data provided is in the following form: studentName numOf BoxesSold.

Consider the following program:
--> Program: Counter-Controlled Loop
--> This program computes and outputs the total number of boxes of Cookies sold, the total revenue, and the average number of Boxes sold by each volunteer.

Sample Run: In this sample run, the user input is shaded.

Enter the number of volunteers: 5
Enter the volunteer's name and the number of boxes sold: Sara 120
Enter the volunteer's name and the number of boxes sold: Ali 128
Enter the volunteer's name and the number of boxes sold: Rana 359
Enter the volunteer's name and the number of boxes sold: Alia 267
Enter the volunteer's name and the number of boxes sold: Raheem 165
The total number of boxes sold: 1039
Enter the cost of one box: 3.50
The total money made by selling cookies: $3636.50
The average number of boxes sold by each volunteer: 207

Comments