Topic: Nested for-loop Question: Which part of the code you need to alter so that the inner loops iterates n times, where n is a positive integer input by the user. In other words, let the user decide how many days to consider just as the choose how many students to consider.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Topic: Nested for-loop

Question: Which part of the code you need to alter so that the inner loops iterates n times, where n is a positive integer input by the user. In other words, let the user decide how many days to consider just as the choose how many students to consider.

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

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY