hey everyone, I wrote a code about a die game that is working very well, but I decided to use the class to learn more about it... so I just used what I wrote before but using the class...unfortunately even if everything complies correctly I don't get the right result anymore...
this is a part of my code...
Code:
void game::start()
{
cout<<"choose your option: \n";
cout<<"1. play\n";
cout<<"2. exit\n";
cin>>f;
srand(time(NULL));
while (f==1)
{
for(x=1; x<=player; x++){
int a,b;
a = rand()%(HIGH-LOW+1)+LOW;
b = rand()%(HIGH-LOW+1)+LOW;
cout<<"x is: "<<x<<"\n";
result[x-1][0]= x;
cout<<"player number:"<<result[x-1][0]<<"\n"; //here I got the right results for all the players
result[x-1][1]= a+b;
cout<<"player result:"<< result[x-1][1]<<"\n";
}
for(x=1; x<=player; x++){ //here I just get the last player result and all the previous players become the last player???
cout<<"player "<<result[x-1][0]<< " total [" <<result[x-1][1]<< "] point ["<<result[x-1][2]<<"]\n";
}
so as you see in the first for loop I get the different results for each players... but when I asked for the same results (second loop) I only get the last player result for all the players...
for example in hte first loop I will have result[0][0]=1 and result[0][1]=7 and result[1][0]=2 and result[1][1]=9
but in the second loop I will have result[0][0]=2 and result[0][1]=9 result[1][0]=2 and result[1][1]=9 why is that???????
do I need to allocate the 2d array dynamically?
tahnks for your help