finding the highest value help

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2004
Posts: 573
Reputation: Dark_Omen is an unknown quantity at this point 
Solved Threads: 5
Dark_Omen Dark_Omen is offline Offline
Posting Pro

finding the highest value help

 
-1
  #1
Nov 7th, 2004
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 10
Reputation: kunal_ktr is an unknown quantity at this point 
Solved Threads: 0
kunal_ktr kunal_ktr is offline Offline
Newbie Poster

Re: finding the highest value help

 
0
  #2
Nov 8th, 2004
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;
}
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 573
Reputation: Dark_Omen is an unknown quantity at this point 
Solved Threads: 5
Dark_Omen Dark_Omen is offline Offline
Posting Pro

Re: finding the highest value help

 
0
  #3
Nov 8th, 2004
Thanks for the help.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC