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.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter5: Repetition Statements
Section: Chapter Questions
Problem 7PP
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage