GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 21-Jun-2004, 06:09
enggwaqas enggwaqas is offline
New Member
 
Join Date: May 2004
Posts: 20
enggwaqas is on a distinguished road

Assigning random values


i am going to make domino game in c. The first step is to assigning random values from pre assigned array to two different arrays and compare them, so that no member of both arrays are identical...the code is given below which is not working properly and i want to use any other way to assign random numbers then random() function....
CPP / C++ / C Code:
int values[10][2]={{0,0},{0,1},{0,2},{0,3},{0,4},
     							{0,5},{0,6},{1,1},{1,2},{1,3}};
 int comp[5][2], huma[5][2];

 void check(int [][2], int);
 int main()
     {

     int j=0,h,x;

     //randomize();
     for(j=j; j<5; j++)
        {
        x=random(10);
        comp[j][0]=values[x][0];
        comp[j][1]=values[x][1];
        }

     for(j=0; j<5; j++)
         for(h=1; h<5; h++)
         if( comp[j][0] == comp[h][0] && comp[j][1] == comp[h][1] )
             {
             check(comp,h);
             }
     //////////////////////////////FOR HUMAM/////////////////////////////
     j=x=0;
     //randomize();
     for(j=j; j<5; j++)
        {
        x=random(10);
        huma[j][0]=values[x][0];
        huma[j][1]=values[x][1];
        }

     for(j=0; j<5; j++)
         for(h=1; h<6; h++)
         if(huma[j][0] == huma[h][0] && huma[j][1] == huma[h][1])
             {
             check(huma,h);
             }
     ///////////////////////COMPARING BOTH ARRAYS///////////////////////
     for(j=0; j<5; j++)
        for(h=0; h<5; h++)
         if(huma[j][0] == comp[h][0] && huma[j][1] == comp[h][1])
             {
             check(huma,j);
             }

     cout<<endl;
     /////////////////////////PRINTING VALUES///////////////////////
     for(j=0; j<5; j++)
         cout<<comp[j][0]<<" "<<comp[j][1]<<endl;

     cout<<endl;

     for(j=0; j<5; j++)
         cout<<huma[j][0]<<" "<<huma[j][1]<<endl;
     getch();
     return 0;
     }

 void check(int array[10][2], int j)
      {
      int x;
      randomize();
      x=random(10);
      array[j][0]=values[j][0];
      array[j][1]=values[j][1];
      }
Last edited by dsmith : 21-Jun-2004 at 07:47. Reason: Please use [c] & [/c] for syntax highlightin
  #2  
Old 21-Jun-2004, 08:27
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Hi enggwaqas.

What do you mean that the code isn't working? Is it crashing the computer or just not giving the results that you expected?

Also, what compiler/OS are you using? The function random is not standard, you should use rand instead. Also, I have never seen the randomize function before so I don't think it is standard either. Look into using srand and rand instead.

Anyway, if you can give us some more info, perhaps we can take a look at this.

Cheers,
d
  #3  
Old 22-Jun-2004, 00:16
enggwaqas enggwaqas is offline
New Member
 
Join Date: May 2004
Posts: 20
enggwaqas is on a distinguished road
the code that i was supplied in my previous post was not giving result properly i.e. it was assigning mutiple values to different cards..but now i have fixed this error by chaning the code completely and using nested structures array, instead of simple array.

Quote:
Originally Posted by dsmith
Also, what compiler/OS are you using? The function random is not standard, you should use rand instead. Also, I have never seen the randomize function before so I don't think it is standard either. Look into using srand and rand instead.

Im using Turbo C++ 4.5 / Borland C++ 5.0....
I have used random(int ) which is defined in stdlib header file to generate random numbers within specified limit, 0-28 in this program, instead of rand() which generate random numbers within RAND_MAX limit & randomize() is used before both random and rand to randomize on every run.

I have completed the shuffling part of my program. Now next step will be displaying graphical cards...when user press right/left button then approproate card will be highlited...some ideas are required from you
  #4  
Old 22-Jun-2004, 10:43
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 570
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
I'm assuming then that your initial question has been solved. I can't help you with the graphics, but there may be someone else here that can... if your first problem hasn't been solved, I can help with that.
__________________
-Aaron
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
store values skyloon MySQL / PHP Forum 6 23-Jul-2005 03:29
Need a script for selecting random tabels and from those tabels selecting random ques mlt MySQL / PHP Forum 2 12-Sep-2003 09:01
getting values zuzupus MySQL / PHP Forum 2 07-Aug-2003 04:33
Random no longer JUST random... JdS GIDTopsites™ 0 12-Jan-2003 09:57

Network Sites: GIDNetwork · GIDApp · GIDBlog · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 21:51.


vBulletin, Copyright © 2000 - 2017, Jelsoft Enterprises Ltd.