+ 5

Why isn't this code working though it was working perfectly earlier ???

Here is a code to calculate mean of element stored in a vector data. float mean= 0.0; for (int index=0; index <data.size();index ++) mean = mean + (data[index])/data.size(); At first it gave correct values for mean but don't know why it gives back 0 as result now.

27th May 2018, 8:16 AM
Junaid Siddiqui
Junaid Siddiqui - avatar
3 Réponses
+ 8
Thanks Duc Van Khanh Tran I copied the code to another compiler and it worked Thanks
28th May 2018, 8:20 PM
Junaid Siddiqui
Junaid Siddiqui - avatar
+ 1
I think you should write the whole code again on another page. I had similar problems (even though I'm using a different language), and I had to write down the whole code again (not just copy and paste) on another page like... twice or three times, and it worked perfectly again. I know it's tiring but try to bear with it... I hope that helps you.
28th May 2018, 3:06 AM
Duc Van Khanh Tran
Duc Van Khanh Tran - avatar
+ 1
+Junaid Siddiqui Just copy and paste?! You’re so lucky!!😂
28th May 2018, 10:06 PM
Duc Van Khanh Tran
Duc Van Khanh Tran - avatar