All I need to know is how a good way to make sure integers between 1 and 52 wont be draw twice over in a for statement... I was thinking something like

srand (time(NULL));
int *drawn;            //The card to be drawn
int notdraw[52];    // All the cards that have already been drawn and should not be drawn again...
for (n=0;n<52;n++)
{
*drawn = new int;
drawn =  rand() % 52+1;
drawn = notdraw[n]
delete draw;
}

thats where I get jumbled up... Just been thinking of putting a for statement in that will process the drawn to look over every notdrawn and ensure its not using one of them... um did I just answer my own question... anyway plz help

yeah sorry guys I had been thinkin about it for a while but posting this unclogged my mind, a little snippet of how I did it

#include<iostream>
#include<stdlib.h>
#include<time.h>
#include<string>
using namespace std;

int main(){
      srand (time(NULL));
      int *drawn;
      int nodraw[52];
      for (int n=0;n<52;n++)
      {
      drawn = new int;
      *drawn = rand() %52+1;
     
      cout << n+1 << ". " <<*drawn << endl;
       for(int x=n;x>0;x--)
      {
              if (*drawn == nodraw[x])
              {
                       cout << "Repeat" << endl;
                       }
      nodraw[n]=*drawn;
              }
      delete drawn;
      }
      system("PAUSE");
      }

sorry guys...

to just draw 52 cards in random order without duplicate draws, just fill an array/vector of size 52 with values [1,52] and do a std::random_shuffle on it.
to make 52 draws, marking/discarding duplicate draws, we can avoid the 52 linear searches:

#include <iostream>
#include <cstdlib>
#include <ctime>

int main()
{
  std::srand( std::time(0) ) ;
  enum { NCARDS = 52 } ;
  bool already_drawn[NCARDS] = { false } ;
  for( int n=0 ; n<NCARDS ; ++n )
  {
    int drawn = rand()%NCARDS + 1 ;
    std::cout << n+1 << ". " << drawn << '\n' ;
    if( already_drawn[drawn-1] ) std::cout << "Repeat\n" ;
    else already_drawn[drawn-1] = true ;
  }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.