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

I need to convert the program below from reading integers to reading floating po

ID: 3630498 • Letter: I

Question

I need to convert the program below from reading integers to reading floating point inputs:
#include <stdio.h>

int main (void)
{
int number, sum, count;
double average;
int max=0;
FILE *in;

in = fopen ("/ece/www/ism2008/hw3/scores.dat", "r");


sum = 0;
count = 0;


while (fscanf (in, "%d", &number) != EOF)
{
sum = sum + number;
if(max<number)
max=number;
count = count + 1;
}
fclose (in);


printf ("Number of scores read: %d ",
count);

printf ("The highest of the scores is %d ",max);

average = (double)sum / count;
printf ("The average of the scores is %5.2lf. ",average);

return (0);
}

Explanation / Answer

It would've been helpful to provide your data file as well for testing, but since you didn't I just went with logic and so this should work "theoretically", it compiles and runs but all I get is 0.00 since it doesn't have any data to manipulate. Hope this helps. If it's not exactly what you wanted then send me a PM to inbox with your explanation and data and we can modify this.

#include <stdio.h>

int main (void)
{
float number, sum;
float max = 0;
int count;
double average;

FILE *in;

in = fopen ("/ece/www/ism2008/hw3/scores.dat", "r");


sum = 0;
count = 0;


while (fscanf (in, "%f", &number) != EOF)
{
  sum = sum + number;
  if( max < number)
   max = number;
  count++;
}
fclose (in);


printf ("Number of scores read: %d ", count);

printf ("The highest of the scores is %f ", max);

average = (double)sum / count;

printf ("The average of the scores is %.2f. ", average);

return (0);

}

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