## Pascal

Moderators: None (Apply to moderate this forum)
Number of posts: 14007

This Forum Only

How do i write a Pascal program that plays a number guessing game Posted by Destiny007 on 6 Apr 2003 at 9:29 AM
This message was edited by Destiny007 at 2003-4-6 9:38:33

I need to write a number guessing game that displys the following chracteristics:

1. The computer thinks of a random number between 1 and 30
2. The player is prompted to type in their guess
3. The computer provides one of the following feedback statements based on the players guess:
- The number the player guessed is to low
- The number the player guessed is to high
- the number the player guessed is outside the range of the game (i.e not netween 1 and 30)

4. The game repeats steps 2 and 3 until the player guesses the correct answer where appropriate feedback is given (i.e Well done... you guessed the correct number)

5. The game then asks the player if they would like to play again
* typing Y repeats the game with a new random number
* typing N exits the program

THANKYOU X

Re: How do i write a Pascal program that plays a number guessing game Posted by iDaZe on 6 Apr 2003 at 9:53 AM
This message was edited by iDaZe at 2003-4-6 9:55:3

: This message was edited by Destiny007 at 2003-4-6 9:38:33

: I need to write a number guessing game that displys the following chracteristics:
:
: 1. The computer thinks of a random number between 1 and 30
: 2. The player is prompted to type in their guess
: 3. The computer provides one of the following feedback statements based on the players guess:
: - The number the player guessed is to low
: - The number the player guessed is to high
: - the number the player guessed is outside the range of the game (i.e not netween 1 and 30)
:
: 4. The game repeats steps 2 and 3 until the player guesses the correct answer where appropriate feedback is given (i.e Well done... you guessed the correct number)
:
: 5. The game then asks the player if they would like to play again
: * typing Y repeats the game with a new random number
: * typing N exits the program
:
:
: THANKYOU X
:
:
:
something like this (typed straight into the box so I can't guaranty it's all correct but it should give you an idea)
```var
Again: Char;
Num, Guess: Integer;
begin
Again := 'Y';
Randomize;
while Again = 'Y' do begin
Num := Random( 30 ) + 1;
Guess := -1;
Writeln( 'Go on, guess ...' );
while Guess <> Num do begin
if ( Guess < 0 ) or ( Guess > 30 ) then
WriteLn( 'Out of range' )
else
if Guess < Num then
WriteLn( 'Too low' )
else
if Guess > Num then
WriteLn( 'Too high' )
else
WriteLn( 'Correct' )
end;
WriteLn( 'Play again? (Y/N)' );
end;
end;
end;
```

A small note: I'm a Delphi programmer so I don't know if I used anything that's not in Pascal. If so then you'll have to solve that for yourself[/edit]
Re: How do i write a Pascal program that plays a number guessing game Posted by UltimateEnd on 6 Apr 2003 at 11:33 AM

: A small note: I'm a Delphi programmer so I don't know if I used anything that's not in Pascal. If so then you'll have to solve that for yourself[/edit]
:
randomize is not in pascal. there is a random function, but it's not random, it's a preset list of numbers.
to get random, you'll need to write your own random procedure/function. you can find one in most textbooks, and also on the web.
btw, it's kinda sad to just ask someone to write a whole program for you. it's better to post your current code, then have them debug it!

Re: How do i write a Pascal program that plays a number guessing game Posted by sweeney on 6 Apr 2003 at 1:38 PM
:
: : A small note: I'm a Delphi programmer so I don't know if I used anything that's not in Pascal. If so then you'll have to solve that for yourself[/edit]
: :
: randomize is not in pascal. there is a random function, but it's not random, it's a preset list of numbers.
: to get random, you'll need to write your own random procedure/function. you can find one in most textbooks, and also on the web.
: btw, it's kinda sad to just ask someone to write a whole program for you. it's better to post your current code, then have them debug it!
:
:
I agree with you on one thing the writeing the hole program thing! but not the randomizeing! you can random any set of numbers and call that number back, simple just randomize; then random(your array 0 to 29); to give you 30 numbers! what pascal are you using by the why? turbo pascal just look up the help menue and look up random! it will tell you about it and give you a little example!!!

Sweeney
Re: How do i write a Pascal program that plays a number guessing game Posted by UltimateEnd on 6 Apr 2003 at 2:46 PM

: :
: I agree with you on one thing the writeing the hole program thing! but not the randomizeing! you can random any set of numbers and call that number back, simple just randomize; then random(your array 0 to 29); to give you 30 numbers! what pascal are you using by the why? turbo pascal just look up the help menue and look up random! it will tell you about it and give you a little example!!!
:
: Sweeney
:
i've used turbo pascal 7, 5.5, and tpw 1.5 for windows.
i know it has a built in random procedure, but if you look closely, you'll see that the "random" numbers are actually a predertmined list.
just run a program that prints 10 random numbers. close it, run it again, the numbers are the same! if you write your own, it's much more efficient.
Re: How do i write a Pascal program that plays a number guessing game Posted by sweeney on 6 Apr 2003 at 3:32 PM
:
: : :
: : I agree with you on one thing the writeing the hole program thing! but not the randomizeing! you can random any set of numbers and call that number back, simple just randomize; then random(your array 0 to 29); to give you 30 numbers! what pascal are you using by the why? turbo pascal just look up the help menue and look up random! it will tell you about it and give you a little example!!!
: :
: : Sweeney
: :
: i've used turbo pascal 7, 5.5, and tpw 1.5 for windows.
: i know it has a built in random procedure, but if you look closely, you'll see that the "random" numbers are actually a predertmined list.
: just run a program that prints 10 random numbers. close it, run it again, the numbers are the same! if you write your own, it's much more efficient.
:
Yea but the pogram the guy wants is very basic, I wrote the same pogram agies ago! and its fine! I used the random function!

sweeney
Re: How do i write a Pascal program that plays a number guessing game Posted by Manning on 7 Apr 2003 at 6:29 AM
:
: : :
: : I agree with you on one thing the writeing the hole program thing! but not the randomizeing! you can random any set of numbers and call that number back, simple just randomize; then random(your array 0 to 29); to give you 30 numbers! what pascal are you using by the why? turbo pascal just look up the help menue and look up random! it will tell you about it and give you a little example!!!
: :
: : Sweeney
: :
: i've used turbo pascal 7, 5.5, and tpw 1.5 for windows.
: i know it has a built in random procedure, but if you look closely, you'll see that the "random" numbers are actually a predertmined list.
: just run a program that prints 10 random numbers. close it, run it again, the numbers are the same! if you write your own, it's much more efficient.
:

That's because it uses a constant seed. To use a random seed, you have to call the Randomize() function first, which you pointed out incorrectly as not being part of Pascal. It is definitely there in TP7, im not sure about 5.5 or TPW though.
Re: How do i write a Pascal program that plays a number guessing game Posted by UltimateEnd on 7 Apr 2003 at 5:38 PM

: That's because it uses a constant seed. To use a random seed, you have to call the Randomize() function first, which you pointed out incorrectly as not being part of Pascal. It is definitely there in TP7, im not sure about 5.5 or TPW though.
:
i believe you, i'm just saying its not in the versions i've used. but if it works, use it, it only makes sense :p!
Re: How do i write a Pascal program that plays a number guessing game Posted by Manning on 8 Apr 2003 at 6:07 AM
:
: : That's because it uses a constant seed. To use a random seed, you have to call the Randomize() function first, which you pointed out incorrectly as not being part of Pascal. It is definitely there in TP7, im not sure about 5.5 or TPW though.
: :
: i believe you, i'm just saying its not in the versions i've used. but if it works, use it, it only makes sense :p!
:

Well you said you've used TP7, and it is in TP7, so it is in a version you've used :)
Re: How do i write a Pascal program that plays a number guessing game Posted by zibadian on 6 Apr 2003 at 11:19 PM
:
: : A small note: I'm a Delphi programmer so I don't know if I used anything that's not in Pascal. If so then you'll have to solve that for yourself[/edit]
: :
: randomize is not in pascal. there is a random function, but it's not random, it's a preset list of numbers.
: to get random, you'll need to write your own random procedure/function. you can find one in most textbooks, and also on the web.
: btw, it's kinda sad to just ask someone to write a whole program for you. it's better to post your current code, then have them debug it!
:
:
I know that randomize is part of TP6+ and FreePascal. To get truly random numbers call Randomize once every 100 or 150 numbers.

## Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic