Logo
Articles Compilers Libraries Books MiniBooklets Assembly C++ Rust Go Linux CPU Others Videos
Advertisement

Article by Ayman Alheraki on January 11 2026 10:32 AM

Example Simple Number Guessing Game
Are you remember that nice days of programming, this is a first programming language I learned in 1986.

GW-BASIC Example from the 1980s

GW-BASIC was a simple programming language developed by Microsoft in the 1980s. It was widely used on IBM-compatible PCs and allowed users to write simple programs that could run directly from the MS-DOS environment. GW-BASIC is an interpreted language, meaning that each line of code is executed as it is read, which was particularly useful for beginners.

Here's a classic example of a GW-BASIC program from the 1980s that demonstrates some basic programming concepts like loops, conditionals, and input/output operations.

Example: Simple Number Guessing Game

This program is a simple number-guessing game where the computer randomly picks a number between 1 and 100, and the player has to guess the number. The computer provides feedback whether the guessed number is too high or too low until the correct number is guessed.

Explanation of the Code

  1. Lines 10-20: These lines print introductory messages to the screen, welcoming the player to the game and explaining the rules.

  2. Line 30: The RANDOMIZE TIMER statement initializes the random number generator using the system timer. This ensures that a different random number is generated each time the program runs.

  3. Line 40: The program generates a random number between 1 and 100 using the RND function. The INT function converts the floating-point number produced by RND into an integer.

  4. Line 50: The program prompts the player to enter a guess using the INPUT statement.

  5. Lines 60-80: These lines contain conditional checks using IF statements to determine if the player's guess is too low, too high, or correct. If the guess is incorrect, the program provides feedback and asks for another guess.

  6. Line 90: If the player's guess is incorrect, the program uses the GOTO statement to loop back to line 50 and prompt for another guess.

  7. Line 100: Once the correct number is guessed, the program prints a closing message and ends with the END statement.

Running the Program

To run this program on a GW-BASIC interpreter (as was common in the 1980s):

  1. Open GW-BASIC: Load the GW-BASIC interpreter on your MS-DOS machine or emulator.

  2. Enter the Code: Type the lines of code exactly as written above.

  3. Run the Program: Type RUN and press Enter.

Conclusion

This example highlights the simplicity and interactive nature of GW-BASIC, which made it an ideal language for beginner programmers in the 1980s. Programs like this number guessing game helped many aspiring developers learn the basics of programming logic, loops, conditionals, and user input/output operations.

Advertisements

Responsive Counter
General Counter
1276446
Daily Counter
1686