int numStudents , student;
float numHours, total , average;
int day ,n; // these are the counters for the loops
cout << " This program will find the average number of hours a day "
<< "that a student spent programming over a long weekend\n\n" ;
cout << "How many students are there ? " << endl << endl;
cin >> numStudents;
cout << "Enter the number of days in the long weekend" << endl;
cin >> n;
for ( student = 1 ; student <= numStudents ; student++)
total = 0 ;
for (day = 1 ; day <= n; day++)
cout << "Please enter the number of hours worked by student "
<< student << " on day " << day << "." << endl;
cin >> numHours;
total = total + numHours;
average = total / 3;
cout << endl;
cout << "The average number of hours per day spent programming "
<< " by student " << student << " is " << average
<< endl << endl << endl;
its giving wrong output , tried initializing n = 0 ; but that was even worse , please tell me what i'm missing ,
ok will at the link so that i will know how to use the code tag.
if i input 2 students , 2 days of the weekend , hours worked on day 1 = 4 and day2 = 6 average by student 1 must be 5 but its giving me 3.3333
i thought maybe i had to initialise n to 0 but its making the output worse
in the sense that where its supposed to ask the user to enter hours worked on day1 and day2 it will now just say day0 .
How many students are there
Enter the number of days in the long weekend
Please enter the number of hours worked by student1 on day1
please enter the number of hours worked by student1 on day2
The average number of hours spent programming by student 1 is 3.3333
but the answer should be 5 so how can i fix my code so as to obtain the correct answer