Questiona Nole that the inner loop of this program is alvays executed exacty three times- once for each day of the long weekend. Which part ot the code you need to alter so that the Inner loop iterates n times, where n is a positve integer inçut by the user. In other words, let the user decide haw many days to consider just as they choose haw many students to cansider.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Topic: Nested for-loop

Question is at the bottom.

I/ This program finds the average time spent programming by a student //
each day over a three-day period.
#include <iostream>
using namespace std;
int main()
{
int numStudents;
float numHours, total, average; int student, day
Il these are the counters for the loops
VERI
cout << "This program will find the average number of
OM
<" hours a day that a student spent programming"
<<" over a long weekend\n\n"; cout
<< "How many students are there? "; cin
>> numStudents;
for(student = 1; student <= numStudents; student++)
{ total = 0;
for(day = 1; day <= 3; day++)
{
cout << "Please enter the number of hours "
<<"worked by student "
DANAL
Transcribed Image Text:I/ This program finds the average time spent programming by a student // each day over a three-day period. #include <iostream> using namespace std; int main() { int numStudents; float numHours, total, average; int student, day Il these are the counters for the loops VERI cout << "This program will find the average number of OM <" hours a day that a student spent programming" <<" over a long weekend\n\n"; cout << "How many students are there? "; cin >> numStudents; for(student = 1; student <= numStudents; student++) { total = 0; for(day = 1; day <= 3; day++) { cout << "Please enter the number of hours " <<"worked by student " DANAL
stdent ee" cn day
ch -nmaurs
total = total + nomHours
J end or inner loop average
= total/s
cout e ena; cout ee "The average
number of hours per
eday spent programming by
e "student" ee student e "ise verage
e endi eeenai eeena
Jwend of outer loop retum
Samplo Run:
UM
This program will ind the averago number of hours a day that a studart apant
programming over a long weekend
How many students are there? 2
Please enter the number of hours worked by student 1 an day 1
Ploaso entor tho number of hours worked by studen: 1 cn day 3 5
The average number of hours per day spent programming by stulent 1 is 5
OMNIA
Please enser the number of hours worked by sudent 2 an day 1 9
Please enter the nurmber of hours worked by studen! 2 cn day 2
13
Please enter the number of hours worked by student 1 on day 3
6
The averaga number of hours per day spent programming by studant 2 is9
QUestione
Note that the inner loop of this program is always executed exactly three limes- once for
each day of the long weskend. Which part of the code you need to alter so that the Inner
loop ierates n times, where nis a posive integer inçut by the user, In other words, let the
user decide haow many days to consider justastheychoose how many students to oansider.
MIN
Transcribed Image Text:stdent ee" cn day ch -nmaurs total = total + nomHours J end or inner loop average = total/s cout e ena; cout ee "The average number of hours per eday spent programming by e "student" ee student e "ise verage e endi eeenai eeena Jwend of outer loop retum Samplo Run: UM This program will ind the averago number of hours a day that a studart apant programming over a long weekend How many students are there? 2 Please enter the number of hours worked by student 1 an day 1 Ploaso entor tho number of hours worked by studen: 1 cn day 3 5 The average number of hours per day spent programming by stulent 1 is 5 OMNIA Please enser the number of hours worked by sudent 2 an day 1 9 Please enter the nurmber of hours worked by studen! 2 cn day 2 13 Please enter the number of hours worked by student 1 on day 3 6 The averaga number of hours per day spent programming by studant 2 is9 QUestione Note that the inner loop of this program is always executed exactly three limes- once for each day of the long weskend. Which part of the code you need to alter so that the Inner loop ierates n times, where nis a posive integer inçut by the user, In other words, let the user decide haow many days to consider justastheychoose how many students to oansider. MIN
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Types of Loop
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education