#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    6
    Rep Power
    0

    Array arithmetic


    Solved!
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,162
    Rep Power
    2222
    In percentageCalculation, the for-loop ain't got no body:
    Code:
    void percentageCalculation()
    {
    	int x;
    	for (x = 0; x < candNum; x++);
    	{
    		percentages[x] = ((totalVotes / 100) * votes[x]);
    	}
    }
    You might want to lose that semicolon.
  4. #3
  5. Wiser? Not exactly.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    5,947
    Rep Power
    4033
    You have a ; after your for loop in the percentageCalculation function. As a result, the body of the for loop is empty and what appears to be the body is actually being run after the loop when x=5 which causes it to overrun your array bounds and corrupt the memory.

    edit: beat to the punch.
    Recycle your old CD's, don't just trash them



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    6
    Rep Power
    0
    Wow, unbelievable. Thanks a lot guys!
  8. #5
  9. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,162
    Rep Power
    2222
    It is very rude and counter-productive to remove the original post. There are many more lurkers than participants here. One day, somebody else will come here via a search engine with the same problem and now that somebody will not be able to benefit from your experience.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    6
    Rep Power
    0
    Originally Posted by dwise1_aol
    It is very rude and counter-productive to remove the original post. There are many more lurkers than participants here. One day, somebody else will come here via a search engine with the same problem and now that somebody will not be able to benefit from your experience.
    I had not considered that, but I understand. However, this was a simple syntax error resulting from a missing semicolon. Still, I'll keep this in mind for future posts.

    Comments on this post

    • b49P23TIvg disagrees : The problem was an extra semi-colon. Not one missing.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    30
    Rep Power
    1
    It is very rude and counter-productive to remove the original post. There are many more lurkers than participants here. One day, somebody else will come here via a search engine with the same problem and now that somebody will not be able to benefit from your experience.
    ++ for this..
    agrees totally with dwise1_aol !!

IMN logo majestic logo threadwatch logo seochat tools logo