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

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 Programmer's 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 its 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

Destiny007Destiny007 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

PLEASE PLEASE HELP IVE TRIED AND AM STRUGGLING SO ID APPRECIATE IT LOADS IF SOMEBODY COULD HELP

THANKYOU X


Comments

  • iDaZeiDaZe 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
    :
    : PLEASE PLEASE HELP IVE TRIED AND AM STRUGGLING SO ID APPRECIATE IT LOADS IF SOMEBODY COULD HELP
    :
    : 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
    ReadLn( Guess );
    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)' );
    Read( Again );
    end;
    end;
    end;
    [/code]

    [edit]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]
  • UltimateEndUltimateEnd Posts: 21Member

    : [edit]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!

  • sweeneysweeney Posts: 117Member
    :
    : : [edit]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
  • UltimateEndUltimateEnd 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.
  • sweeneysweeney 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
  • zibadianzibadian Posts: 6,349Member
    :
    : : [edit]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.
  • ManningManning 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.
  • UltimateEndUltimateEnd 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!
  • ManningManning 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 :)
Sign In or Register to comment.