This should work!

I can not figure out why this code compiles but doesn't display what I expect! I thought it would show me five random card picked form the deck.

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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;


//*******function

int seed();
int randRange (int low, int high);
void setup_deck();
void draw5();

//*******end of functions


//******Global variables

string faces[13] = {"Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King", "Ace"};
static int x = 0;
static int y = 0;
static int z = 0;
int card1;
int card2;
int card3;
int card4;
int card5;

//*****End of Globals


   struct buildDeck
   {
       int vaule;
       string face;
       string suite;
   };

buildDeck card[52];

//****all possible cards in a deck are listed with all card info//
void setup_deck()
{
//building all the hearts
     for(int i = 0; i<13; i++)
 {
     card[i].vaule = i;
     card[i].face = faces[i];
     card[i].suite ="HEARTS";
 }
//building all the spades
    for(int j =13; j<26; j++)
 {
     card[j].vaule = x;
     card[j].face = faces[x];
     card[j].suite ="SPADES";
     x++;
 }
//building all the diamonds
for(int k=26; k<39; k++)
{
    card[k].vaule=y;
    card[k].face = faces[y];
    card[k].suite ="DIAMONDS";
    y++;
}
//building all the clubs
for(int l=39; l<52; l++)
{
    card[l].vaule=z;
    card[l].face = faces[z];
    card[l].suite="CLUBS";
    z++;
}
}


int seed()
{
srand( time(NULL));
}


int randRange (int low, int high)
{
  return rand() % (high - low + 1) + low;
}


void draw5()
{
    bool success = true;
    do
    {
        card1 = randRange(0,51);
        card2 = randRange(0,51);
        card3 = randRange(0,51);
        card4 = randRange(0,51);
        card5 = randRange(0,51);
    if( card1 != card2 && card2 != card3 && card3 != card4 && card4 != card5)
    {
        success = false;
    }
    }while( success = true);

}


int main()
{
seed();
setup_deck();
draw5();

cout<<"First card is : "<<card[card1].face<<"\n";
cout<<"Second card is : "<<card[card2].face<<"\n";
cout<<"Third card is : "<<card[card3].face<<"\n";
cout<<"Fourth card is : "<<card[card4].face<<"\n";
cout<<"Fifth card is : "<<card[card5].face<<"\n";


}
what does it display
The stander out is blank; I think it is some sort of run time error. The compiler takes the code but the logic is flawed somewhere and I don't know where.
On Line 104

while( success = true);.

Needed To Be

while( success == true);

I can not figure out why this code compiles

It does not compile for me.

for example: you have a method that returns an int (sedd() ), but you don't bother returning anything.
Thanks so much sanndy1911 with that fixed the code works! now I can move on to the next step of displaying the cards and then making a game.

mutexe do you mean the seed() functions? I am using that call to send the current time to srand so that I can randRange any where in main and get a new random number.

Thanks for the help!
sanddy1911 was correct.on line 104
Topic archived. No new replies allowed.