selecting random value from enumerated set

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
#include <iostream>
using namespace std;

int main ( )
{

int ace, score, cards_wanted, random_number; 


char space, first_try;
space=' ';

enum numbers {one=1, two=2, three=3, four=4, five=5, six=6, seven=7,
eight=8, nine=9, jack=10, queen=10, king=10};

first_try=numbers;

cout << "How many cards?" << space <<endl;
cin  >> cards_wanted;

switch (cards_wanted)
       {
                     case 2:
             cout << "Next Card?" << first_try;
             cout << "Next Card?" << first_try;
       break;
}
switch (cards_wanted)
       {
                     case 3:
             cout << "next Card?" << first_try;
             cout << "next Card?" << first_try;
             cout << "next Card?" << first_try;
       break;
             }
             
             }


Having trouble in this section
1
2
3
4
enum numbers {one=1, two=2, three=3, four=4, five=5, six=6, seven=7,
eight=8, nine=9, jack=10, queen=10, king=10};

first_try=numbers;


I want the computer to select a random value from the enumerated set numbers. I get the compiler error that it expected a primary expression before ;

Another easy question, Appreciate any help.
What made you think an enumerator could give you something random?

1
2
enum numbers {one=1, two=2, three=3, four=4, five=5, six=6, seven=7,
eight=8, nine=9, jack=10, queen=10, king=10};


You've basically made a data type for yourself. Thus you can do something like:
1
2
3
4
5
6
7
8
9
10
int sum(numbers x, numbers y)
{
  return x + y;
}

int main(void)
{
  numbers x = four, y = seven;
  // and whathaveyou
}
If you are wanting to "deal" cards it's probably better to construct a deck and randomly pull from it. Cards, decks and hands are a good way to learn and play around with OO theory too.
Topic archived. No new replies allowed.