Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmers Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use it's exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

How do i write a Pascal program that plays a number guessing game

Posts: 4Member
[b][red]This message was edited by Destiny007 at 2003-4-6 9:38:33[/red][/b][hr]
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

· ·

• Posts: 464Member
[b][red]This message was edited by iDaZe at 2003-4-6 9:55:3[/red][/b][hr]
: [b][red]This message was edited by Destiny007 at 2003-4-6 9:38:33[/red][/b][hr]
: 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)
[code]
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;
[/code]

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]
· ·
• Posts: 21Member

: 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!

· ·
• Posts: 117Member
:
: : 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
· ·
• Posts: 21Member

: :
: 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.
· ·
• Posts: 117Member
:
: : :
: : 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
· ·
• Posts: 6,349Member
:
: : 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.
· ·
• Posts: 1,621Member
:
: : :
: : 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.
· ·
• Posts: 21Member

: 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!
· ·
• Posts: 1,621Member
:
: : 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 :)
· ·