problem with changing a value

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
string generate_random_card(string& card_value,string card_suit )
// uses the generate card suit and generate card value functions to make a card and sets the string variable card equal to that. then 
// returns the string card.
{   
    card_suit=(generate_random_suit());
    card_value= generate_random_value();
    string card= (card_value+card_suit);
    cout<<"generating card\n";
    return(card);
} 

void generate_hand(string& card_value, string& card_suit, string hand[])
//uses random card function and for loop to fill an array called hand
//which is an array of strings holding a suit and value of a card
{ 
     for (int i = 0; i<NUMBER_OF_CARDS_IN_A_HAND; i++)
      {
           
           hand[i]=(generate_random_card(card_value,card_suit));
      }    
}

void check_if_hand_is_legal(string hand[])
{
     string card_value;
     string card_suit;
     int i=1;
     while(i<5)
     {
               if(hand[0]==hand[i])
               {
                     hand[i]==generate_random_card(card_value,card_suit);
                     cout<<"1 is same as "<<i+1<<endl;
               }
               i++;
     }
     i=2;
     while(i<5)
     {
               if(hand[1]==hand[i])
               {
                     hand[i]=generate_random_card(card_value,card_suit);
                     cout<<"2 is same as "<<i+1<<endl;
               }
               i++;
     }
     i=3;
     while(i<5)
     {
               if(hand[2]==hand[i])
               {
                     hand[i]=generate_random_card(card_value,card_suit);
                     cout<<"3 is same as "<<i+1<<endl;
               }
               i++;
     }
     i=4;
     while(i<5)
     {
               if(hand[3]==hand[i])
               {
                     hand[i]=generate_random_card(card_value,card_suit);
                     cout<<"4 is same as "<<i+1<<endl;
               }
               i++;
     }    
     
     
}             

int main(int argc, char *argv[])
{   int count=0;
    string card_value="!";
    string card_suit="!";
    string card[52];
    string hand[NUMBER_OF_CARDS_IN_A_HAND];
    
          generate_hand(card_value,card_suit,hand);
          check_if_hand_is_legal(hand);
          for(int i=0;i<5;i++)
           {
           cout<<i+1<<" "<<hand[i]<<endl;
           }
    
    system("PAUSE");
    return EXIT_SUCCESS;
}


the check if hand is legal function is supposed to check if the card is legal and change it if it isn't. it seems to be checking and recognizing that one is illegal then says its generating a new card but it ends up giving doubles anyway. and another problem it seems to generate the same hand everytime anyway. can anyone help?
Last edited on
Topic archived. No new replies allowed.