home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / cplus / 13586 < prev    next >
Encoding:
Text File  |  1992-09-13  |  1.8 KB  |  81 lines

  1. Path: sparky!uunet!sun-barr!cs.utexas.edu!uwm.edu!ogicse!emory!nntp.msstate.edu!cee1
  2. From: cee1@ra.msstate.edu (Charles Evans)
  3. Newsgroups: comp.lang.c++
  4. Subject: Problems with int as enum
  5. Message-ID: <1992Sep13.222623.21562@ra.msstate.edu>
  6. Date: 13 Sep 92 22:26:23 GMT
  7. Article-I.D.: ra.1992Sep13.222623.21562
  8. Organization: Mississippi State University
  9. Lines: 70
  10.  
  11. BC++ 2.0 :
  12.  
  13. (Trying to learn some C++ here in my spare time.. well the first real program
  14. in book I am using, "C++ for C Programmers", has this  [edited for brevity])
  15.  
  16. #include <stream.h>
  17. #include <stdlib.h>          // optional
  18.  
  19. int random(void);
  20.  
  21. enum suit { clubs, diamonds, hearts, spades };
  22.  
  23. struct card { suit s; int pips };
  24.  
  25. ...
  26.  
  27. void init_deck(card d[])
  28. {
  29.     for (int i = 0; i < 52; ++i)
  30.     {
  31.         d[i].s = (i / 13);   // enum as int ? -- WARNING #1
  32.         d[i].pips = 1 + i % 13;
  33.     }
  34. }
  35. void shuffle(card d[])
  36. {
  37.     for (int i = 0; i < 52; ++i)
  38.     {
  39.         int k = random() % 52     // choose a random card
  40.         card t = d[i];        // swap two cards ERROR #2, #3
  41.         d[i] = d[k];
  42.         d[k] = t;        // ERROR #4
  43.     }
  44. }
  45.  
  46. ....
  47.  
  48. int main(void)
  49. {
  50.     card deck[52];
  51.  
  52.     init_deck(deck);
  53.     pr_deck(deck);
  54.     shuffle(deck);
  55.     pr_deck(deck);
  56.     return(0);
  57. }
  58.  
  59. -----
  60.  
  61. WARNING #1 : Assigning int to suit in function init_deck(card far*)
  62. ERROR #2 : Undefined symbol 'card' in function shuffle(card far*)
  63. ERROR #3 : Undefined symbol 't' in function shuffle(card far*)
  64. ERROR #4 : Undefined symbol 't' in function shuffle(card far*)
  65.  
  66. ---
  67.  
  68. So whats the problem with swapping 'cards'? cant you define a 'card t'??
  69. Help. No clue.
  70. No sleep.
  71.  
  72. chuck
  73.  
  74.  
  75.  
  76. -- 
  77. +--------------------+-----------------------+------------------------+
  78. |  Charles E. Evans  |  cee1@ra.msstate.edu  |  All things are green  |
  79. |    iDLE CHATTEr    |  cee1@MSSTATE.BITNET  |  unless they are not.  |
  80. +--------------------+-----------------------+------------------------+
  81.