Answered You can hire a professional tutor to get the answer.

QUESTION

Save your program to the file t6. Read floating point values from stdin, each separated by a newline, and terminated by EOF. The input values are in...

  1. Save your program to the file t6.c.
  2. Read floating point values from stdin, each separated by a newline, and terminated by EOF.
  3. The input values are in the range [-100,000 to +100,000].
  4. The input will contain at least one floating-point value.
  5. The input may contain blank lines: these should be ignored.
  6. Apart from possible blank lines, the input is otherwise well-formed.
  7. At EOF, output:
  8. The smallest value seen.
  9. The largest value seen.
  10. The arithmetic mean of all the values seen.
  11. All output must be accurate to two decimal places.
  12. The output values must be separated by a single space character and followed by a newline character.
  13. Examples:
  • Input:
75.66
  • Output:
5.60 7.00 6.20
  • Input:
11
  • Output:
11.00 11.00 11.00

Above is the requirements for my homework and below is the code that I've written for it. My code works unfortunately for some reason it doesn't meet the requirements. Can someone please take a look and help me modify my code? Thank you!

#include<stdio.h>

#include<limits.h>

#include<stdlib.h>

int main(){

  int n = 0,i,usr_input;

  float mean, max, min = INT_MAX, sum = 0.0, num[n];

  for(i = 0; i<=n; i++){

      usr_input = scanf("%f",&num[i]);

      sum = sum + num[i];

      n++;

      mean = sum / (n-1);

      if(usr_input == EOF){

       printf("%0.2f %0.2f %0.2fn",max,min,mean);

       exit(0);

      }

      if(i==0){

          max = num[i];

          min = num[i];

      }

      if(max < num[i]){

          max = num[i];  

      }

      if(min > num[i]){

          min = num[i];

      }

  }

}

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question