


  Program Number_Guesser;
         { Simple Number Guessing Game }

     uses CRT; { so you can do screen stuff }

     Const  { const will make a value constant through out the entire }
            { program.}

         Max_Num_Guess = 3;  { sets the maximum number of guess to 3 }

{---------------------------------------------------------------------}

     var   { variables are temporary storage for information }
           { like for the variable Number, it will hold the random }
           { number the computer will generate }

           { since these variables are in the beggining of the }
           { program, they will be constant through out the entire }
           { program. But their value can be changed. }

         Number : integer;   { actual number that computer makes }
         Guess  : integer;   { what you guess }
         times  : integer;   { number of times you guessed it }

{---------------------------------------------------------------------}

  Procedure Get_Number;  { This procedure will get the }
                         { random number generated by the }
                         { computer }
            begin
             randomize;  { this will start the random generator }
                         { It is built in the compiler }

             Number:=random(5)+1;  { will give the variable Number }
                                     { a random number from 1 to 100 }
  end;

  Procedure Display_Loser_Screen;   { this will display the losing screen }
    begin
    writeln;
    writeln('  Game Over. You lose. You suck. ');
    writeln('  The number was ',number,'.');
  end;

  Procedure DIsplay_Winner_screen; { this will display the winning screen }
    begin
     writeln;
     writeln(' Hurray. You got the number.');
     Writeln(' It only took you ',times,' tries to guess it.');
  end;

  Procedure Main;
    var ch  : char;  { variable will only read characters }

            begin
              Get_Number; { this procedure must be called to get a random }
                          { number }

              clrscr;    { clear everything in the screen }

              times:=0;  { sets the number of times you guess to 0 }

              writeln;writeln;  { this will make it skip two lines }
              writeln(' Try to guess a number from 1 to 5.');
              writeln(' You have ',max_num_guess,' guesses.');
                      { by adding ,times, inside a writeln statement, }
                      { it'll display the value of times inside the string }
                      { or group of letters "strung" together }
              writeln;
               repeat   { this statement will start a loop }
                        { everything under it will continue to loop }
                        { around and around.......}
                 write(' Guess a number : ');  { doing a write statement }
                                               { is the same as writeln  }
                                               { except for it doesn't   }
                                               { continue onto the next line}

                 readln(guess);   { will let the user input a number }
                                  { since the variable Guess is an integer, }
                                  { if you try to enter a letter or string }
                                  { then the program will crash. }
                                  { There are ways to avoid this but that'll }
                                  { be in another program...}

                 times:=times + 1;  { This will increase the value of Times }
                                    { by 1. }
                   if Guess > Number then writeln(' Too High ');
                   if Guess < Number then writeln(' Too Low ');
                     { This is standard easy to understand logical math }
                     { If what you guess is greater than or lower than the }
                     { number, then tell the range of it }

               until (Guess=Number) or (Times=Max_Num_Guess);
                     { the loop will repeat until Guess is equal number or }
                     { if you run out of guess which means times will be }
                     { equal to 3. Change it to increase the number of times}
                     { you can guess. }

                if Guess=Number then Display_Winner_Screen
                 else Display_Loser_Screen;  { displays winning or losing }
                                             { depending on what happen }
                                             { you did }

                writeln;
              writeln(' Do you want to try again?(Y/N)');
              ch:=upcase(readkey); { lets you enter a key }
                                   { Upcase will convert what you entered }
                                   { into uppercase }

               if ch='Y' then Main; { if the user enters of Y then the }
                                    { procedure Main will repeat }
                                    { if not then procedure ends }

           end;


           { the main program will start everything }
  begin
   Main;
  end.


