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

  1. Newsgroups: comp.lang.c++
  2. From: nikki@trmphrst.demon.co.uk (Nikki Locke)
  3. Path: sparky!uunet!pipex!demon!trmphrst.demon.co.uk!nikki
  4. ReplyTo: nikki@trmphrst.demon.co.uk
  5. Subject: Re: Problems with int as enum
  6. References: <1992Sep13.222623.21562@ra.msstate.edu>
  7. Distribution: world
  8. X-Mailer: cppnews $Revision: 1.16 $
  9. Organization: Trumphurst Ltd.
  10. Lines: 58
  11. Date: Tue, 15 Sep 1992 11:40:18 +0000
  12. Message-ID: <716582418snx@trmphrst.demon.co.uk>
  13. Sender: usenet@gate.demon.co.uk
  14.  
  15.  
  16. In article <1992Sep13.222623.21562@ra.msstate.edu> cee1@ra.msstate.edu (Charles Evans) writes:
  17.  
  18. > BC++ 2.0 :
  19. > (Trying to learn some C++ here in my spare time.. well the first real program
  20. > in book I am using, "C++ for C Programmers", has this  [edited for brevity])
  21. > #include <stream.h>
  22. > #include <stdlib.h>          // optional
  23. > int random(void);
  24. > enum suit { clubs, diamonds, hearts, spades };
  25. > struct card { suit s; int pips };
  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. You are assigning an integer to an enum. You need a cast here ...
  33.         d[i].s = (suit)(i / 13);
  34.  
  35. >         d[i].pips = 1 + i % 13;
  36. >     }
  37. > }
  38. > void shuffle(card d[])
  39. > {
  40. >     for (int i = 0; i < 52; ++i)
  41. >     {
  42. >         int k = random() % 52     // choose a random card
  43. You have a missing semicolon here, which causes the other errors ...
  44.         int k = random() % 52;     // choose a random card
  45.  
  46. >         card t = d[i];        // swap two cards ERROR #2, #3
  47. >         d[i] = d[k];
  48. >         d[k] = t;        // ERROR #4
  49. >     }
  50. > }
  51. > ...
  52. > -----
  53. > WARNING #1 : Assigning int to suit in function init_deck(card far*)
  54. > ERROR #2 : Undefined symbol 'card' in function shuffle(card far*)
  55. > ERROR #3 : Undefined symbol 't' in function shuffle(card far*)
  56. > ERROR #4 : Undefined symbol 't' in function shuffle(card far*)
  57. > ---
  58. ---
  59. Nikki Locke              |                        | nikki@trmphrst.demon.co.uk
  60. Trumphurst Ltd.          | Tel: +44 (0)691-670318 | nikki@cix.compulink.co.uk
  61. PC and Unix consultancy  | Fax: +44 (0)691-670316 | nikki@kewill.co.uk
  62. trmphrst.demon.co.uk is NOT affiliated with ANY other sites at demon.co.uk.
  63. Demon.co.uk is a dial-up subscription access point to the Internet.
  64.