Error reading file

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jun 2005
Posts: 2,052
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: Error reading file

 
0
  #11
Jul 9th, 2005
The average is 76.4666.

desidude, since your sum and count are modified after the while loop, only the last value of your numbers gets added to sum, and count gets incremented once, from zero to one. And 77 is your last value.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 60
Reputation: zyruz is an unknown quantity at this point 
Solved Threads: 5
zyruz zyruz is offline Offline
Junior Poster in Training

Re: Error reading file

 
0
  #12
Jul 9th, 2005
Just put the
  1. sum = sum+val;
  2. count=count++;
inside your while loop, and it shuld work.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 15
Reputation: desidude is an unknown quantity at this point 
Solved Threads: 0
desidude desidude is offline Offline
Newbie Poster

Re: Error reading file

 
0
  #13
Jul 9th, 2005
Zyruz, i tried that before but it gives 74.78 which is 1047( 100 less than total(1147))/14(it is suppose to be 15).
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,778
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 744
Team Colleague
Narue's Avatar
Narue Narue is online now Online
Code Goddess

Re: Error reading file

 
0
  #14
Jul 9th, 2005
Don't forget to account for the first value:
  1. if ( fin >> val )
  2. {
  3. sum += val;
  4. ++count;
  5. min = max = val;
  6.  
  7. while ( fin >> val )
  8. {
  9. if ( val < min )
  10. {
  11. min = val;
  12. }
  13.  
  14. if ( val > max )
  15. {
  16. max = val;
  17. }
  18.  
  19. sum += val;
  20. ++count;
  21. }
  22. }
On a side note, this is very, very wrong:
  1. count=count++;
It modifies count twice between sequence points, which is undefined.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 15
Reputation: desidude is an unknown quantity at this point 
Solved Threads: 0
desidude desidude is offline Offline
Newbie Poster

Re: Error reading file

 
0
  #15
Jul 9th, 2005
thx alot guys
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC