Question

So my code looks like this

**Procedure DisplayMenu;
  Begin
    Repeat
      Writeln('Hello, ' ,PlayerName);
      Writeln('1. Be Guesser');
      Writeln('2. Let The Computer Guess');
      Writeln('9. Quit');
      Readln(MainMenuChoice);
    *Until MainMenuChoice=(1) or (2) or (9);*
  End; //Procedure//**

And I would be very grateful if someone could explain to me where I have gone wrong.

I think the error is with the Until MainMenuChoice=(1) or (2) or (9); part.

Was it helpful?

Solution

You are comparing the value of MainMenuChoice to the value created by OR'ing the bits of the three test values together, which produces 11. So your code is actually doing this:

Until MainMenuChoice = 11; 

To compare it again the three individual values, use a Set instead:

Until MainMenuChoice in [1, 2, 9];

However, assuming MainMenuChoice is a Char then Readln() is going to return the character that the user actually typed, not its numeric value, so use this instead:

Until MainMenuChoice in ['1', '2', '9'];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top