Write a program that finds the average time spent programming by a student each
ID: 3749922 • Letter: W
Question
Write a program that finds the average time spent programming by a student each day over a 3 day period. Hints and what program should include: Must use Nested for Loops. Prompt the user for the number of students. Prompt the user for the time spent programming by each student for each of the 3 days, this should be iin hours Print to the screen the average number of hours per day spent programming by each student. Label the output to include the student number. Output Run: 4 Students. Student 1 (5, 5, 5); Student 2 (8 2 1 Student 3 (4 25 15 Student 4(3 7 0)Explanation / Answer
#include<iostream>
using namespace std;
int main()
{
int n;
//reading number of students
cout<<"Enter number of students:";
cin>>n;
//declaring array;
double student[n];
int i=1;
while(i<=n)//loop
{
int j=1;
double x,s=0;
cout<<" Student "<<i<<endl;
while(j<=3)//nested loop
{
//reading hours
cout<<" Time spent programming on day "<<j<<"(in hours) :"<<endl;
cin>>x;
s=s+x;
j++;
}
student[i-1]=s/3;//computing average
i++;
}
//displaying output
i=1;
cout<<" Student Average_Time_spent ";
while(i<=n)
{
//displaying output
cout<<"Student "<<i<<" "<<student[i-1]<<endl;
i++;
}
return 0;
}
output:
Enter number of students:4
Student 1
Time spent programming on day 1(in hours) :
5
Time spent programming on day 2(in hours) :
5
Time spent programming on day 3(in hours) :
5
Student 2
Time spent programming on day 1(in hours) :
8
Time spent programming on day 2(in hours) :
2
Time spent programming on day 3(in hours) :
1
Student 3
Time spent programming on day 1(in hours) :
4
Time spent programming on day 2(in hours) :
2.5
Time spent programming on day 3(in hours) :
1.5
Student 4
Time spent programming on day 1(in hours) :
3
Time spent programming on day 2(in hours) :
7
Time spent programming on day 3(in hours) :
0
Student Average_Time_spent
Student 1 5
Student 2 3.66667
Student 3 2.66667
Student 4 3.33333
Process exited normally.
Press any key to continue . . .
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.