   Help with array assignment...
  I'm trying to get an array assignment loop to work and it seems to work but the output is wrong.  It's not making sense to me but then I'm an Uber Noob.  Anywho, here is the code: #include <iostream.h>int main(){int playerScore[8];for(int i=0;i<8;i++){   cout << "player " << i << " has a score of " << playerScore[i] << endl;}int twoScore[1];twoScore[0]=100;twoScore[1]=101;cout << twoScore[0] << endl << twoScore[1];return 0;}And here is the output:player 0 has a score of -858993460player 1 has a score of -858993460player 2 has a score of -858993460player 3 has a score of -858993460player 4 has a score of -858993460player 5 has a score of -858993460player 6 has a score of -858993460player 7 has a score of -858993460100101As you can see the scores don't get initalized the way I think they should.  I put the second half of the code in there just to see if I can do a simple array assignment and get the right values to print out.  It's strange to me because I see that "i" is the correct value of 0-7 but playerScore is totally screwed.Thanks for any help you can give.  [edited by - McB41n on February 19, 2004 12:10:36 PM]
  1) Don''t use  in regular posts, it translates into italics.  Include your post inside [ source ] tags.<br><br>2) In C/C++, when a variable is created it contains "random" values.  You must initialize all variables before their use.  <br><br>i.e.<br><br>   <!–STARTSCRIPT–><pre class="source"><br><font color=blue>int</font> playerscore[<font color=purple>8</font>];<br><font color=gray>// initialize array<br></font><br><font color=blue>for</font>(<font color=blue>int</font> loop = 0; loop &lt; 8; ++loop ) { playerscore[<font color=purple>loop</font>] = 0; }<br></pre><!–ENDSCRIPT–>    <br><br><HR><SMALL> [ <a href="http://home.comcast.net/~jeffschiller2/">Little Devils Inc.</a> ]</SMALL>   ;    When you declare variable in a function (main for your example) data are not initialize. In your code you don't initilize your array then you have a random value.  Moreover you have forget to tell which playerScore you want to print. try that : #include <iostream.h>int main(){int playerScore[8];for(int i=0;i<8;i++){playerScore[i] = 0;cout << "player " << i << " has a score of " << playerScore[i] << endl;}int twoScore[1];twoScore[0]=100;twoScore[1]=101;cout << twoScore[0] << endl << twoScore[1];return 0;}  [edited by - Arsouille on February 19, 2004 12:09:42 PM];  Thanks for the tip on posting and initializing.  I fixed my post, now I''ll play with the code!Thanks again,McB41n ;  ICE TO SEE YOU MCBAIN.... MENDOZAAAAAAAAAA ;  If your array is not to big you could just do this: int playerScore[8]={99,77,88,44,55,77,33,66};  to initalize your array to whatever values you want before you use it.  If God played dice, He''d win.—Ian Stewart, Does God Play Dice? The Mathematics of Chaos ;  Sure, but it''d be better to make the solution scalable right? 