Home » Archimedes archive » Acorn User » AU 1995-04.adf » !C_C » c/numgame

c/numgame

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Archimedes archive » Acorn User » AU 1995-04.adf » !C_C
Filename: c/numgame
Read OK:
File size: 0E6F bytes
Load address: 0000
Exec address: 0000
File contents
/* Program to demonstrate multiple if statements, switch constructions,
infinite for loops and do-while loops as well as random number
generation! */
/* Acorn User 'C for yourself' demonstration C program - April 1995 */

#include <stdio.h>
#include <stdlib.h>

main ()
{
   int   number = 0;
   int   chance = 0;
   int   guess = 0, correct = 0;
   int   choice = 0;
   float temp = 0.0;

   printf("Number guesser\n--------------\n\n");
   printf("You have ten chances to guess a number between 0 and 100.\n\n");
   printf("Please enter a positive integer to 'seed' the number generator.\n");
   scanf("%d",&number);
   while (getchar() != '\n');
   if (number < 0) number = -number;
   srand(number);
    
   for ( ; ; ) {

      /* This is an infinite 'for' loop, and the only way the program
      can terminate is through the 'return' statement towards the end
      of the code */

      temp = (float) rand() / (float) RAND_MAX;

      /* The above statement scales the random number generated by the
      'rand()' function into a floating point number between 0 and 1.
      'rand()' and RAND_MAX are predefined in ANSI C. */

      number = 100*temp;

      /* Now the fraction has been used to pick an integer between
      0 and 100 */

      correct = 0;
   
      for (chance = 1; chance <= 10; chance ++) {
         printf("Please enter guess no. %d:\n",chance);
         guess = 0;
         scanf("%d",&guess);
         while (getchar() != '\n') ;

         /* The 'while' statement above cleans the input after the
         scanf function. If this wasn't performed and the user entered
         something odd such as a string instead of an integer, the program
         would get somewhat confused and further input would be
         corrupted. */

         if (guess < number) {
            printf("Sorry, you're too low.\n");
         } else if (guess > number) {
            printf("Nope - too high.\n");
         } else {
            printf("Congratulations! Spot on!\n");
            correct = 1;
            break;
         }

         /* This is a multiple 'if' construction - note that a maximum of two
         comparisons are made. If 'guess' isn't smaller or larger than
         'number', then they must be equal. The 'correct' flag is used to
         determine which end-of-game message to print. */

      }
   
      if (correct == 1) {
         printf("Well done - you guessed the mystery number.\n");
      } else {
         printf("Sorry, you didn't guess the number - it was %d.\n",number);
      }

      /* An if-else statement */
   
      do {
         printf("1: Play again\n");
         printf("2: Quit program\n");

         scanf("%d",&choice);
         while (getchar() != '\n') ;

         switch(choice) {
         case 1:
            /* Don't need to do anything here */
            break;
         case 2:
            printf("Thanks for playing. Bye!\n");
            return;
            break;
         default:
            printf("Sorry - I didn't recognise that response.\n");
            printf("Please choose again.\n\n");
         }

         /* A 'switch' construction that responds to the integers 1 and
         2 - any other values cause the default case to be executed. */

      } while (choice < 1 || choice > 2);

      /* The do-while loop keeps iterating until the user picks a valid
      option - if an invalid option is picked, the 'default' case is
      executed. The 'break' statement terminates the do-while loop and so
      passes control back to the infinite for loop, which starts the game
      once more. The 'return' statement terminates the 'main()' function,
      and so stops the program completely. */

   }
}
00000000  2f 2a 20 50 72 6f 67 72  61 6d 20 74 6f 20 64 65  |/* Program to de|
00000010  6d 6f 6e 73 74 72 61 74  65 20 6d 75 6c 74 69 70  |monstrate multip|
00000020  6c 65 20 69 66 20 73 74  61 74 65 6d 65 6e 74 73  |le if statements|
00000030  2c 20 73 77 69 74 63 68  20 63 6f 6e 73 74 72 75  |, switch constru|
00000040  63 74 69 6f 6e 73 2c 0a  69 6e 66 69 6e 69 74 65  |ctions,.infinite|
00000050  20 66 6f 72 20 6c 6f 6f  70 73 20 61 6e 64 20 64  | for loops and d|
00000060  6f 2d 77 68 69 6c 65 20  6c 6f 6f 70 73 20 61 73  |o-while loops as|
00000070  20 77 65 6c 6c 20 61 73  20 72 61 6e 64 6f 6d 20  | well as random |
00000080  6e 75 6d 62 65 72 0a 67  65 6e 65 72 61 74 69 6f  |number.generatio|
00000090  6e 21 20 2a 2f 0a 2f 2a  20 41 63 6f 72 6e 20 55  |n! */./* Acorn U|
000000a0  73 65 72 20 27 43 20 66  6f 72 20 79 6f 75 72 73  |ser 'C for yours|
000000b0  65 6c 66 27 20 64 65 6d  6f 6e 73 74 72 61 74 69  |elf' demonstrati|
000000c0  6f 6e 20 43 20 70 72 6f  67 72 61 6d 20 2d 20 41  |on C program - A|
000000d0  70 72 69 6c 20 31 39 39  35 20 2a 2f 0a 0a 23 69  |pril 1995 */..#i|
000000e0  6e 63 6c 75 64 65 20 3c  73 74 64 69 6f 2e 68 3e  |nclude <stdio.h>|
000000f0  0a 23 69 6e 63 6c 75 64  65 20 3c 73 74 64 6c 69  |.#include <stdli|
00000100  62 2e 68 3e 0a 0a 6d 61  69 6e 20 28 29 0a 7b 0a  |b.h>..main ().{.|
00000110  20 20 20 69 6e 74 20 20  20 6e 75 6d 62 65 72 20  |   int   number |
00000120  3d 20 30 3b 0a 20 20 20  69 6e 74 20 20 20 63 68  |= 0;.   int   ch|
00000130  61 6e 63 65 20 3d 20 30  3b 0a 20 20 20 69 6e 74  |ance = 0;.   int|
00000140  20 20 20 67 75 65 73 73  20 3d 20 30 2c 20 63 6f  |   guess = 0, co|
00000150  72 72 65 63 74 20 3d 20  30 3b 0a 20 20 20 69 6e  |rrect = 0;.   in|
00000160  74 20 20 20 63 68 6f 69  63 65 20 3d 20 30 3b 0a  |t   choice = 0;.|
00000170  20 20 20 66 6c 6f 61 74  20 74 65 6d 70 20 3d 20  |   float temp = |
00000180  30 2e 30 3b 0a 0a 20 20  20 70 72 69 6e 74 66 28  |0.0;..   printf(|
00000190  22 4e 75 6d 62 65 72 20  67 75 65 73 73 65 72 5c  |"Number guesser\|
000001a0  6e 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 5c  |n--------------\|
000001b0  6e 5c 6e 22 29 3b 0a 20  20 20 70 72 69 6e 74 66  |n\n");.   printf|
000001c0  28 22 59 6f 75 20 68 61  76 65 20 74 65 6e 20 63  |("You have ten c|
000001d0  68 61 6e 63 65 73 20 74  6f 20 67 75 65 73 73 20  |hances to guess |
000001e0  61 20 6e 75 6d 62 65 72  20 62 65 74 77 65 65 6e  |a number between|
000001f0  20 30 20 61 6e 64 20 31  30 30 2e 5c 6e 5c 6e 22  | 0 and 100.\n\n"|
00000200  29 3b 0a 20 20 20 70 72  69 6e 74 66 28 22 50 6c  |);.   printf("Pl|
00000210  65 61 73 65 20 65 6e 74  65 72 20 61 20 70 6f 73  |ease enter a pos|
00000220  69 74 69 76 65 20 69 6e  74 65 67 65 72 20 74 6f  |itive integer to|
00000230  20 27 73 65 65 64 27 20  74 68 65 20 6e 75 6d 62  | 'seed' the numb|
00000240  65 72 20 67 65 6e 65 72  61 74 6f 72 2e 5c 6e 22  |er generator.\n"|
00000250  29 3b 0a 20 20 20 73 63  61 6e 66 28 22 25 64 22  |);.   scanf("%d"|
00000260  2c 26 6e 75 6d 62 65 72  29 3b 0a 20 20 20 77 68  |,&number);.   wh|
00000270  69 6c 65 20 28 67 65 74  63 68 61 72 28 29 20 21  |ile (getchar() !|
00000280  3d 20 27 5c 6e 27 29 3b  0a 20 20 20 69 66 20 28  |= '\n');.   if (|
00000290  6e 75 6d 62 65 72 20 3c  20 30 29 20 6e 75 6d 62  |number < 0) numb|
000002a0  65 72 20 3d 20 2d 6e 75  6d 62 65 72 3b 0a 20 20  |er = -number;.  |
000002b0  20 73 72 61 6e 64 28 6e  75 6d 62 65 72 29 3b 0a  | srand(number);.|
000002c0  20 20 20 20 0a 20 20 20  66 6f 72 20 28 20 3b 20  |    .   for ( ; |
000002d0  3b 20 29 20 7b 0a 0a 20  20 20 20 20 20 2f 2a 20  |; ) {..      /* |
000002e0  54 68 69 73 20 69 73 20  61 6e 20 69 6e 66 69 6e  |This is an infin|
000002f0  69 74 65 20 27 66 6f 72  27 20 6c 6f 6f 70 2c 20  |ite 'for' loop, |
00000300  61 6e 64 20 74 68 65 20  6f 6e 6c 79 20 77 61 79  |and the only way|
00000310  20 74 68 65 20 70 72 6f  67 72 61 6d 0a 20 20 20  | the program.   |
00000320  20 20 20 63 61 6e 20 74  65 72 6d 69 6e 61 74 65  |   can terminate|
00000330  20 69 73 20 74 68 72 6f  75 67 68 20 74 68 65 20  | is through the |
00000340  27 72 65 74 75 72 6e 27  20 73 74 61 74 65 6d 65  |'return' stateme|
00000350  6e 74 20 74 6f 77 61 72  64 73 20 74 68 65 20 65  |nt towards the e|
00000360  6e 64 0a 20 20 20 20 20  20 6f 66 20 74 68 65 20  |nd.      of the |
00000370  63 6f 64 65 20 2a 2f 0a  0a 20 20 20 20 20 20 74  |code */..      t|
00000380  65 6d 70 20 3d 20 28 66  6c 6f 61 74 29 20 72 61  |emp = (float) ra|
00000390  6e 64 28 29 20 2f 20 28  66 6c 6f 61 74 29 20 52  |nd() / (float) R|
000003a0  41 4e 44 5f 4d 41 58 3b  0a 0a 20 20 20 20 20 20  |AND_MAX;..      |
000003b0  2f 2a 20 54 68 65 20 61  62 6f 76 65 20 73 74 61  |/* The above sta|
000003c0  74 65 6d 65 6e 74 20 73  63 61 6c 65 73 20 74 68  |tement scales th|
000003d0  65 20 72 61 6e 64 6f 6d  20 6e 75 6d 62 65 72 20  |e random number |
000003e0  67 65 6e 65 72 61 74 65  64 20 62 79 20 74 68 65  |generated by the|
000003f0  0a 20 20 20 20 20 20 27  72 61 6e 64 28 29 27 20  |.      'rand()' |
00000400  66 75 6e 63 74 69 6f 6e  20 69 6e 74 6f 20 61 20  |function into a |
00000410  66 6c 6f 61 74 69 6e 67  20 70 6f 69 6e 74 20 6e  |floating point n|
00000420  75 6d 62 65 72 20 62 65  74 77 65 65 6e 20 30 20  |umber between 0 |
00000430  61 6e 64 20 31 2e 0a 20  20 20 20 20 20 27 72 61  |and 1..      'ra|
00000440  6e 64 28 29 27 20 61 6e  64 20 52 41 4e 44 5f 4d  |nd()' and RAND_M|
00000450  41 58 20 61 72 65 20 70  72 65 64 65 66 69 6e 65  |AX are predefine|
00000460  64 20 69 6e 20 41 4e 53  49 20 43 2e 20 2a 2f 0a  |d in ANSI C. */.|
00000470  0a 20 20 20 20 20 20 6e  75 6d 62 65 72 20 3d 20  |.      number = |
00000480  31 30 30 2a 74 65 6d 70  3b 0a 0a 20 20 20 20 20  |100*temp;..     |
00000490  20 2f 2a 20 4e 6f 77 20  74 68 65 20 66 72 61 63  | /* Now the frac|
000004a0  74 69 6f 6e 20 68 61 73  20 62 65 65 6e 20 75 73  |tion has been us|
000004b0  65 64 20 74 6f 20 70 69  63 6b 20 61 6e 20 69 6e  |ed to pick an in|
000004c0  74 65 67 65 72 20 62 65  74 77 65 65 6e 0a 20 20  |teger between.  |
000004d0  20 20 20 20 30 20 61 6e  64 20 31 30 30 20 2a 2f  |    0 and 100 */|
000004e0  0a 0a 20 20 20 20 20 20  63 6f 72 72 65 63 74 20  |..      correct |
000004f0  3d 20 30 3b 0a 20 20 20  0a 20 20 20 20 20 20 66  |= 0;.   .      f|
00000500  6f 72 20 28 63 68 61 6e  63 65 20 3d 20 31 3b 20  |or (chance = 1; |
00000510  63 68 61 6e 63 65 20 3c  3d 20 31 30 3b 20 63 68  |chance <= 10; ch|
00000520  61 6e 63 65 20 2b 2b 29  20 7b 0a 20 20 20 20 20  |ance ++) {.     |
00000530  20 20 20 20 70 72 69 6e  74 66 28 22 50 6c 65 61  |    printf("Plea|
00000540  73 65 20 65 6e 74 65 72  20 67 75 65 73 73 20 6e  |se enter guess n|
00000550  6f 2e 20 25 64 3a 5c 6e  22 2c 63 68 61 6e 63 65  |o. %d:\n",chance|
00000560  29 3b 0a 20 20 20 20 20  20 20 20 20 67 75 65 73  |);.         gues|
00000570  73 20 3d 20 30 3b 0a 20  20 20 20 20 20 20 20 20  |s = 0;.         |
00000580  73 63 61 6e 66 28 22 25  64 22 2c 26 67 75 65 73  |scanf("%d",&gues|
00000590  73 29 3b 0a 20 20 20 20  20 20 20 20 20 77 68 69  |s);.         whi|
000005a0  6c 65 20 28 67 65 74 63  68 61 72 28 29 20 21 3d  |le (getchar() !=|
000005b0  20 27 5c 6e 27 29 20 3b  0a 0a 20 20 20 20 20 20  | '\n') ;..      |
000005c0  20 20 20 2f 2a 20 54 68  65 20 27 77 68 69 6c 65  |   /* The 'while|
000005d0  27 20 73 74 61 74 65 6d  65 6e 74 20 61 62 6f 76  |' statement abov|
000005e0  65 20 63 6c 65 61 6e 73  20 74 68 65 20 69 6e 70  |e cleans the inp|
000005f0  75 74 20 61 66 74 65 72  20 74 68 65 0a 20 20 20  |ut after the.   |
00000600  20 20 20 20 20 20 73 63  61 6e 66 20 66 75 6e 63  |      scanf func|
00000610  74 69 6f 6e 2e 20 49 66  20 74 68 69 73 20 77 61  |tion. If this wa|
00000620  73 6e 27 74 20 70 65 72  66 6f 72 6d 65 64 20 61  |sn't performed a|
00000630  6e 64 20 74 68 65 20 75  73 65 72 20 65 6e 74 65  |nd the user ente|
00000640  72 65 64 0a 20 20 20 20  20 20 20 20 20 73 6f 6d  |red.         som|
00000650  65 74 68 69 6e 67 20 6f  64 64 20 73 75 63 68 20  |ething odd such |
00000660  61 73 20 61 20 73 74 72  69 6e 67 20 69 6e 73 74  |as a string inst|
00000670  65 61 64 20 6f 66 20 61  6e 20 69 6e 74 65 67 65  |ead of an intege|
00000680  72 2c 20 74 68 65 20 70  72 6f 67 72 61 6d 0a 20  |r, the program. |
00000690  20 20 20 20 20 20 20 20  77 6f 75 6c 64 20 67 65  |        would ge|
000006a0  74 20 73 6f 6d 65 77 68  61 74 20 63 6f 6e 66 75  |t somewhat confu|
000006b0  73 65 64 20 61 6e 64 20  66 75 72 74 68 65 72 20  |sed and further |
000006c0  69 6e 70 75 74 20 77 6f  75 6c 64 20 62 65 0a 20  |input would be. |
000006d0  20 20 20 20 20 20 20 20  63 6f 72 72 75 70 74 65  |        corrupte|
000006e0  64 2e 20 2a 2f 0a 0a 20  20 20 20 20 20 20 20 20  |d. */..         |
000006f0  69 66 20 28 67 75 65 73  73 20 3c 20 6e 75 6d 62  |if (guess < numb|
00000700  65 72 29 20 7b 0a 20 20  20 20 20 20 20 20 20 20  |er) {.          |
00000710  20 20 70 72 69 6e 74 66  28 22 53 6f 72 72 79 2c  |  printf("Sorry,|
00000720  20 79 6f 75 27 72 65 20  74 6f 6f 20 6c 6f 77 2e  | you're too low.|
00000730  5c 6e 22 29 3b 0a 20 20  20 20 20 20 20 20 20 7d  |\n");.         }|
00000740  20 65 6c 73 65 20 69 66  20 28 67 75 65 73 73 20  | else if (guess |
00000750  3e 20 6e 75 6d 62 65 72  29 20 7b 0a 20 20 20 20  |> number) {.    |
00000760  20 20 20 20 20 20 20 20  70 72 69 6e 74 66 28 22  |        printf("|
00000770  4e 6f 70 65 20 2d 20 74  6f 6f 20 68 69 67 68 2e  |Nope - too high.|
00000780  5c 6e 22 29 3b 0a 20 20  20 20 20 20 20 20 20 7d  |\n");.         }|
00000790  20 65 6c 73 65 20 7b 0a  20 20 20 20 20 20 20 20  | else {.        |
000007a0  20 20 20 20 70 72 69 6e  74 66 28 22 43 6f 6e 67  |    printf("Cong|
000007b0  72 61 74 75 6c 61 74 69  6f 6e 73 21 20 53 70 6f  |ratulations! Spo|
000007c0  74 20 6f 6e 21 5c 6e 22  29 3b 0a 20 20 20 20 20  |t on!\n");.     |
000007d0  20 20 20 20 20 20 20 63  6f 72 72 65 63 74 20 3d  |       correct =|
000007e0  20 31 3b 0a 20 20 20 20  20 20 20 20 20 20 20 20  | 1;.            |
000007f0  62 72 65 61 6b 3b 0a 20  20 20 20 20 20 20 20 20  |break;.         |
00000800  7d 0a 0a 20 20 20 20 20  20 20 20 20 2f 2a 20 54  |}..         /* T|
00000810  68 69 73 20 69 73 20 61  20 6d 75 6c 74 69 70 6c  |his is a multipl|
00000820  65 20 27 69 66 27 20 63  6f 6e 73 74 72 75 63 74  |e 'if' construct|
00000830  69 6f 6e 20 2d 20 6e 6f  74 65 20 74 68 61 74 20  |ion - note that |
00000840  61 20 6d 61 78 69 6d 75  6d 20 6f 66 20 74 77 6f  |a maximum of two|
00000850  0a 20 20 20 20 20 20 20  20 20 63 6f 6d 70 61 72  |.         compar|
00000860  69 73 6f 6e 73 20 61 72  65 20 6d 61 64 65 2e 20  |isons are made. |
00000870  49 66 20 27 67 75 65 73  73 27 20 69 73 6e 27 74  |If 'guess' isn't|
00000880  20 73 6d 61 6c 6c 65 72  20 6f 72 20 6c 61 72 67  | smaller or larg|
00000890  65 72 20 74 68 61 6e 0a  20 20 20 20 20 20 20 20  |er than.        |
000008a0  20 27 6e 75 6d 62 65 72  27 2c 20 74 68 65 6e 20  | 'number', then |
000008b0  74 68 65 79 20 6d 75 73  74 20 62 65 20 65 71 75  |they must be equ|
000008c0  61 6c 2e 20 54 68 65 20  27 63 6f 72 72 65 63 74  |al. The 'correct|
000008d0  27 20 66 6c 61 67 20 69  73 20 75 73 65 64 20 74  |' flag is used t|
000008e0  6f 0a 20 20 20 20 20 20  20 20 20 64 65 74 65 72  |o.         deter|
000008f0  6d 69 6e 65 20 77 68 69  63 68 20 65 6e 64 2d 6f  |mine which end-o|
00000900  66 2d 67 61 6d 65 20 6d  65 73 73 61 67 65 20 74  |f-game message t|
00000910  6f 20 70 72 69 6e 74 2e  20 2a 2f 0a 0a 20 20 20  |o print. */..   |
00000920  20 20 20 7d 0a 20 20 20  0a 20 20 20 20 20 20 69  |   }.   .      i|
00000930  66 20 28 63 6f 72 72 65  63 74 20 3d 3d 20 31 29  |f (correct == 1)|
00000940  20 7b 0a 20 20 20 20 20  20 20 20 20 70 72 69 6e  | {.         prin|
00000950  74 66 28 22 57 65 6c 6c  20 64 6f 6e 65 20 2d 20  |tf("Well done - |
00000960  79 6f 75 20 67 75 65 73  73 65 64 20 74 68 65 20  |you guessed the |
00000970  6d 79 73 74 65 72 79 20  6e 75 6d 62 65 72 2e 5c  |mystery number.\|
00000980  6e 22 29 3b 0a 20 20 20  20 20 20 7d 20 65 6c 73  |n");.      } els|
00000990  65 20 7b 0a 20 20 20 20  20 20 20 20 20 70 72 69  |e {.         pri|
000009a0  6e 74 66 28 22 53 6f 72  72 79 2c 20 79 6f 75 20  |ntf("Sorry, you |
000009b0  64 69 64 6e 27 74 20 67  75 65 73 73 20 74 68 65  |didn't guess the|
000009c0  20 6e 75 6d 62 65 72 20  2d 20 69 74 20 77 61 73  | number - it was|
000009d0  20 25 64 2e 5c 6e 22 2c  6e 75 6d 62 65 72 29 3b  | %d.\n",number);|
000009e0  0a 20 20 20 20 20 20 7d  0a 0a 20 20 20 20 20 20  |.      }..      |
000009f0  2f 2a 20 41 6e 20 69 66  2d 65 6c 73 65 20 73 74  |/* An if-else st|
00000a00  61 74 65 6d 65 6e 74 20  2a 2f 0a 20 20 20 0a 20  |atement */.   . |
00000a10  20 20 20 20 20 64 6f 20  7b 0a 20 20 20 20 20 20  |     do {.      |
00000a20  20 20 20 70 72 69 6e 74  66 28 22 31 3a 20 50 6c  |   printf("1: Pl|
00000a30  61 79 20 61 67 61 69 6e  5c 6e 22 29 3b 0a 20 20  |ay again\n");.  |
00000a40  20 20 20 20 20 20 20 70  72 69 6e 74 66 28 22 32  |       printf("2|
00000a50  3a 20 51 75 69 74 20 70  72 6f 67 72 61 6d 5c 6e  |: Quit program\n|
00000a60  22 29 3b 0a 0a 20 20 20  20 20 20 20 20 20 73 63  |");..         sc|
00000a70  61 6e 66 28 22 25 64 22  2c 26 63 68 6f 69 63 65  |anf("%d",&choice|
00000a80  29 3b 0a 20 20 20 20 20  20 20 20 20 77 68 69 6c  |);.         whil|
00000a90  65 20 28 67 65 74 63 68  61 72 28 29 20 21 3d 20  |e (getchar() != |
00000aa0  27 5c 6e 27 29 20 3b 0a  0a 20 20 20 20 20 20 20  |'\n') ;..       |
00000ab0  20 20 73 77 69 74 63 68  28 63 68 6f 69 63 65 29  |  switch(choice)|
00000ac0  20 7b 0a 20 20 20 20 20  20 20 20 20 63 61 73 65  | {.         case|
00000ad0  20 31 3a 0a 20 20 20 20  20 20 20 20 20 20 20 20  | 1:.            |
00000ae0  2f 2a 20 44 6f 6e 27 74  20 6e 65 65 64 20 74 6f  |/* Don't need to|
00000af0  20 64 6f 20 61 6e 79 74  68 69 6e 67 20 68 65 72  | do anything her|
00000b00  65 20 2a 2f 0a 20 20 20  20 20 20 20 20 20 20 20  |e */.           |
00000b10  20 62 72 65 61 6b 3b 0a  20 20 20 20 20 20 20 20  | break;.        |
00000b20  20 63 61 73 65 20 32 3a  0a 20 20 20 20 20 20 20  | case 2:.       |
00000b30  20 20 20 20 20 70 72 69  6e 74 66 28 22 54 68 61  |     printf("Tha|
00000b40  6e 6b 73 20 66 6f 72 20  70 6c 61 79 69 6e 67 2e  |nks for playing.|
00000b50  20 42 79 65 21 5c 6e 22  29 3b 0a 20 20 20 20 20  | Bye!\n");.     |
00000b60  20 20 20 20 20 20 20 72  65 74 75 72 6e 3b 0a 20  |       return;. |
00000b70  20 20 20 20 20 20 20 20  20 20 20 62 72 65 61 6b  |           break|
00000b80  3b 0a 20 20 20 20 20 20  20 20 20 64 65 66 61 75  |;.         defau|
00000b90  6c 74 3a 0a 20 20 20 20  20 20 20 20 20 20 20 20  |lt:.            |
00000ba0  70 72 69 6e 74 66 28 22  53 6f 72 72 79 20 2d 20  |printf("Sorry - |
00000bb0  49 20 64 69 64 6e 27 74  20 72 65 63 6f 67 6e 69  |I didn't recogni|
00000bc0  73 65 20 74 68 61 74 20  72 65 73 70 6f 6e 73 65  |se that response|
00000bd0  2e 5c 6e 22 29 3b 0a 20  20 20 20 20 20 20 20 20  |.\n");.         |
00000be0  20 20 20 70 72 69 6e 74  66 28 22 50 6c 65 61 73  |   printf("Pleas|
00000bf0  65 20 63 68 6f 6f 73 65  20 61 67 61 69 6e 2e 5c  |e choose again.\|
00000c00  6e 5c 6e 22 29 3b 0a 20  20 20 20 20 20 20 20 20  |n\n");.         |
00000c10  7d 0a 0a 20 20 20 20 20  20 20 20 20 2f 2a 20 41  |}..         /* A|
00000c20  20 27 73 77 69 74 63 68  27 20 63 6f 6e 73 74 72  | 'switch' constr|
00000c30  75 63 74 69 6f 6e 20 74  68 61 74 20 72 65 73 70  |uction that resp|
00000c40  6f 6e 64 73 20 74 6f 20  74 68 65 20 69 6e 74 65  |onds to the inte|
00000c50  67 65 72 73 20 31 20 61  6e 64 0a 20 20 20 20 20  |gers 1 and.     |
00000c60  20 20 20 20 32 20 2d 20  61 6e 79 20 6f 74 68 65  |    2 - any othe|
00000c70  72 20 76 61 6c 75 65 73  20 63 61 75 73 65 20 74  |r values cause t|
00000c80  68 65 20 64 65 66 61 75  6c 74 20 63 61 73 65 20  |he default case |
00000c90  74 6f 20 62 65 20 65 78  65 63 75 74 65 64 2e 20  |to be executed. |
00000ca0  2a 2f 0a 0a 20 20 20 20  20 20 7d 20 77 68 69 6c  |*/..      } whil|
00000cb0  65 20 28 63 68 6f 69 63  65 20 3c 20 31 20 7c 7c  |e (choice < 1 |||
00000cc0  20 63 68 6f 69 63 65 20  3e 20 32 29 3b 0a 0a 20  | choice > 2);.. |
00000cd0  20 20 20 20 20 2f 2a 20  54 68 65 20 64 6f 2d 77  |     /* The do-w|
00000ce0  68 69 6c 65 20 6c 6f 6f  70 20 6b 65 65 70 73 20  |hile loop keeps |
00000cf0  69 74 65 72 61 74 69 6e  67 20 75 6e 74 69 6c 20  |iterating until |
00000d00  74 68 65 20 75 73 65 72  20 70 69 63 6b 73 20 61  |the user picks a|
00000d10  20 76 61 6c 69 64 0a 20  20 20 20 20 20 6f 70 74  | valid.      opt|
00000d20  69 6f 6e 20 2d 20 69 66  20 61 6e 20 69 6e 76 61  |ion - if an inva|
00000d30  6c 69 64 20 6f 70 74 69  6f 6e 20 69 73 20 70 69  |lid option is pi|
00000d40  63 6b 65 64 2c 20 74 68  65 20 27 64 65 66 61 75  |cked, the 'defau|
00000d50  6c 74 27 20 63 61 73 65  20 69 73 0a 20 20 20 20  |lt' case is.    |
00000d60  20 20 65 78 65 63 75 74  65 64 2e 20 54 68 65 20  |  executed. The |
00000d70  27 62 72 65 61 6b 27 20  73 74 61 74 65 6d 65 6e  |'break' statemen|
00000d80  74 20 74 65 72 6d 69 6e  61 74 65 73 20 74 68 65  |t terminates the|
00000d90  20 64 6f 2d 77 68 69 6c  65 20 6c 6f 6f 70 20 61  | do-while loop a|
00000da0  6e 64 20 73 6f 0a 20 20  20 20 20 20 70 61 73 73  |nd so.      pass|
00000db0  65 73 20 63 6f 6e 74 72  6f 6c 20 62 61 63 6b 20  |es control back |
00000dc0  74 6f 20 74 68 65 20 69  6e 66 69 6e 69 74 65 20  |to the infinite |
00000dd0  66 6f 72 20 6c 6f 6f 70  2c 20 77 68 69 63 68 20  |for loop, which |
00000de0  73 74 61 72 74 73 20 74  68 65 20 67 61 6d 65 0a  |starts the game.|
00000df0  20 20 20 20 20 20 6f 6e  63 65 20 6d 6f 72 65 2e  |      once more.|
00000e00  20 54 68 65 20 27 72 65  74 75 72 6e 27 20 73 74  | The 'return' st|
00000e10  61 74 65 6d 65 6e 74 20  74 65 72 6d 69 6e 61 74  |atement terminat|
00000e20  65 73 20 74 68 65 20 27  6d 61 69 6e 28 29 27 20  |es the 'main()' |
00000e30  66 75 6e 63 74 69 6f 6e  2c 0a 20 20 20 20 20 20  |function,.      |
00000e40  61 6e 64 20 73 6f 20 73  74 6f 70 73 20 74 68 65  |and so stops the|
00000e50  20 70 72 6f 67 72 61 6d  20 63 6f 6d 70 6c 65 74  | program complet|
00000e60  65 6c 79 2e 20 2a 2f 0a  0a 20 20 20 7d 0a 7d     |ely. */..   }.}|
00000e6f