943,498 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 3524
  • C RSS
Nov 7th, 2004
-1

finding the highest value help

Expand Post »
Hi,
I am new to programming. The program I made reads a list of points from a text file. Then it finds the standard deviation and how many sets of points are in the file. Now I want to find the highest x value from the list and the highest y value from the list. So far I made the variables for these two values and I know I have to use an if statement.

Here is the code:

  1. #include<stdio.h>
  2. #include<math.h>
  3. int main(int argc, char *argv[])
  4. {
  5. FILE *input;
  6. float x, y, sumx, sumy, avex, avey, sumx_sqrd, sumy_sqrd, xmax, ymax;
  7. int count;
  8. if (argc == 1)
  9. {
  10. fprintf(stderr, "You must supply a file name.\n");
  11. return 1;
  12. }
  13. input = fopen(argv[1], "r");
  14. if (input == NULL)
  15. {
  16. fprintf(stderr, "Error opening file \"%s\".\n", argv[1]);
  17. return 1;
  18. }
  19. sumx = 0.0;
  20. sumy = 0.0;
  21. sumx_sqrd = 0.0;
  22. sumy_sqrd = 0.0;
  23. count = 0;
  24. while (fscanf(input, "%f\t%f", &x, &y) != EOF)
  25. {
  26. count++;
  27. sumx += x;
  28. sumy += y;
  29. sumx_sqrd += x * x;
  30. sumy_sqrd += y * y;
  31. }
  32.  
  33. fclose(input);
  34. avex = sumx/count;
  35. avey = sumy/count;
  36. printf("Average of x = %f\n", avex);
  37. printf("Standard deviation of x = %f\n", sqrt(sumy_sqrd/count - avex * avex));
  38. printf("\n");
  39. printf("Average of y = %f\n", avey);
  40. printf("Standard deviation of y = %f\n", sqrt(sumy_sqrd/count - avey * avey));
  41. printf("\n");
  42. printf("The maximum x value is %f\n", );
  43. printf("The maximum y value is %f\n", );
  44. printf("\n");
  45. printf("The number of data sets is %d\n", count);
  46. return 0;
  47. }

Thank You
Last edited by alc6379; Nov 8th, 2004 at 3:42 am. Reason: added [code] tags
Similar Threads
Reputation Points: 23
Solved Threads: 6
Posting Pro
Dark_Omen is offline Offline
573 posts
since Apr 2004
Nov 8th, 2004
0

Re: finding the highest value help

Here is ur modified while statement ....

while (fscanf(input, "%f\t%f", &x, &y) != EOF)
{
count++;
if(count==1)
{ xmax=x; ymax=y;}
else
{if(xmax<x)
xmax=x;
if(ymax<x)
ymax=y; }


sumx += x;
sumy += y;
sumx_sqrd += x * x;
sumy_sqrd += y * y;
}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kunal_ktr is offline Offline
10 posts
since Oct 2004
Nov 8th, 2004
0

Re: finding the highest value help

Thanks for the help.
Reputation Points: 23
Solved Threads: 6
Posting Pro
Dark_Omen is offline Offline
573 posts
since Apr 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: limitations of 10 employees per page
Next Thread in C Forum Timeline: Exiting your program?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC