By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,275 Members | 936 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,275 IT Pros & Developers. It's quick & easy.

Help!, How do I avoid "shorter numbers"...

P: 4
I need average for my program. And I'm using it multiple time in my program.

I'm doing this in PVSS:

So say average float is 2.0013005 (FOR EXAMPLE) but the number in the end can be higher... so my program takes this average and gives me 2.0013 in the log file. After it uses this shorter version for other calculations.instead of my original 2.0013005 (It cuts it and well that should NOT be a problem, but because of the arithmetics I use. This gap adds on with each datapoint and then it results in the slight difference in the end.

MY QUESTION IS, DO YOU KNOW HOW CAN I PREVENT MY PROGRAM FORM GIVING ME A SHORTER NUMBER INSTEAD OF A FULL ONE?



Expand|Select|Wrap|Line Numbers
  1. main ()
  2.  
  3. {    
  4.  
  5.     string s, path_name; 
  6.     file f;  
  7.     int  year1, month1, day1, hour1, min1, sec1, i, N;   // value MOVED to dyn_int
  8.     dyn_float A; //  
  9.     time  ts, TS1, TS2;
  10.     float MD, SD, average, setting, value, sum; 
  11.  
  12. path_name = path_nameG.text;
  13.  
  14. s = TS1_panel.text;
  15. sscanf (s, "%d.%d.%d %d:%d:%d", year1, month1, day1, hour1, min1, sec1);
  16. TS1 = makeTime (year1, month1, day1, hour1, min1, sec1); 
  17.  
  18.  
  19. s = TS2_panel.text;
  20. sscanf (s, "%d.%d.%d %d:%d:%d", year1, month1, day1, hour1, min1, sec1);
  21. TS2 = makeTime (year1, month1, day1, hour1, min1, sec1); 
  22.  
  23. //Button.enabled = FALSE;
  24.  
  25. f = fopen (path_name, "r"); // Have to read in help. parameters here.  
  26.  
  27.  
  28.        //fgets (f, s);  
  29.  
  30.  
  31.  
  32.  
  33.   while (feof(f)==0) {  ///////// (f) --------- in brackets changed to path_name.
  34.  
  35.       fgets (s, 100, f); // INT COUNT MUST BE PROVIDED!  
  36.  
  37.       sscanf (s, "%d.%d.%d %d:%d:%d %f %f", year1, month1, day1, hour1, min1, sec1, setting, value); /// SHOULD BE "f" INSTEAD OF "s"
  38.  
  39.       //DebugN (year1, month1, day1, hour1, min1, sec1, setting, value);
  40.  
  41.       ts = makeTime (year1, month1, day1, hour1, min1, sec1); 
  42.  
  43.        //TS1 - Initial timestamp
  44.       // TS2 - Final timestamp
  45.  
  46.  
  47.       if ((ts >= TS1) && (ts <= TS2)) {          
  48.            // DebugN (ts);
  49.             dynAppend (A, value); //////////// VALUE!!!!!!!!!!!!!!!!111111111 is used in sscanf TOO!
  50.        } 
  51.   } 
  52.  
  53.    int N = dynlen (A); 
  54.  
  55.          sum = 0;
  56.  
  57.   for (int i = 1; i <= N; i++)
  58.  
  59. {
  60.   sum += A[i];
  61.   // sum = sum + A[i]
  62.   } 
  63.  
  64. average = sum/N ;  // AVERAGE    
  65. DebugN (average);
  66.  
  67.  
  68. // Standard Deviation ..........................................
  69.  
  70.   for (int i = 1; i <= N; i++)  {
  71.   //SD=0; //DELE!
  72.      SD += (A[i] - average)*(A[i] - average);
  73.       //sum += A[i];
  74.  
  75.     } 
  76.  
  77. SD = SD/N;
  78.  
  79. SD = sqrt(SD); 
  80.  
  81. TV.text (SD);
  82.  
  83.  // if ((TS2 < TS1) || (TS2 = TS1))  {   // Time Stamp Comparsion  TEMP!
  84.  
  85.  //    TV.text (" Wrong TS input");
  86.  
  87.  
  88.  
  89.  // return 0;  
  90. //}
  91.  
  92.  
  93.  
  94.    }
Oct 2 '07 #1
Share this Question
Share on Google+
1 Reply


Savage
Expert 100+
P: 1,764
Hmm,have you tried using double?

Savage
Oct 2 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.