Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The following code segment is supposed to output the averageof the five numbers

ID: 3613089 • Letter: T

Question

The following code segment is supposed to output the averageof the five numbers on each input line, for all of the lines in thefile. Instead, it simply outputs the sum of all of the numbers inth efile. Whats wrog with the code segment? Change the code to workcorrectly.    sum = 0;       while(indata)    {          cout= 1;          while(count <= 5 && indata)          {                cin>> number;                sum= sum + number;           }          cout<< sum / count << end1;    } The following code segment is supposed to output the averageof the five numbers on each input line, for all of the lines in thefile. Instead, it simply outputs the sum of all of the numbers inth efile. Whats wrog with the code segment? Change the code to workcorrectly.    sum = 0;       while(indata)    {          cout= 1;          while(count <= 5 && indata)          {                cin>> number;                sum= sum + number;           }          cout<< sum / count << end1;    }

Explanation / Answer


      while(indata)    {          cout= 1;
      sum = 0;
         while(count <= 5 && indata)          {                indata>> number;                sum= sum + number;
              count = count + 1;
          }          cout<< (sum * 1.0 / (count-1))<< end1;     //You need to make it float
   }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote