Windows Shell Script Help

khoas

Beta member
Messages
2
Location
USA
Hey guys new to this board and new to scripting as well. The book I'm working with is Microsoft Windows Shell Scripting Programming for the Absolute Beginner. I am tasked with created code for a guessing number game. I have it up and running fine but now I'm trying to modify it a bit and I'm getting lost on how to do this. Any help would be greatly appreciated.


I need to write something that will tell the user that if they get within 200 of the random number they are getting warm and when they get within 20 they are hot.

Also need the program to restart itself based on the player pressing Y. I think I need a loop statement but not sure if I put that outside the last screen indicating the players has guessed the number, or if goes in that same block of code.

As I said any help would be appreciated. Here is my current working code:

@ECHO off

COLOR 0E

CLS


SET RandomNo=%random%

SET /a NoGuesses = 0

SET /b High = 0

SET /c Low = 0


TITLE = T H E G U E S S A N U M B E R G A M E - %RandomNo%


ECHO.
ECHO.
ECHO.
ECHO.
ECHO W E L C O M E T O T H E ..........
ECHO.
ECHO.
ECHO.
ECHO.
ECHO GGGG U U EEE SSSS SSSS AA N N U U M M BBB EEE RRR
ECHO G G U U E S S A A NN N U U MM MM B B E R R
ECHO G U U E SSS SSS AAAA N N N U U M M M M B B E RRR
ECHO G GG U U EEE SSS SSS A A N N N U U M M M BBB EEE RR
ECHO G G U U E S S A A N NN U U M M B B E R R
ECHO GGGG UU EEE SSSS SSSS A A N N UU M M BBB EEE R R
ECHO.
ECHO.
ECHO G A M E ! ! !
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.

PAUSE


:BEGINLOOP

CLS

ECHO.
ECHO.
ECHO.
ECHO.
ECHO.

SET /p UserNumber=Please type your guess:

SET /a NoGuesses += 1

ECHO.
ECHO.
ECHO.
ECHO.
ECHO.



IF %UserNumber% LSS %RandomNo% (

ECHO.
ECHO Your guess was too low. Try again.
ECHO.
ECHO.

SET /a High += 1
PAUSE

GOTO :BEGINLOOP
)

IF %UserNumber% GTR %RandomNo% (

ECHO.
ECHO Your guess was too high. Try again.
ECHO.
ECHO.

SET /a Low += 1
PAUSE

GOTO :BEGINLOOP

)


CLS

COLOR E0

ECHO.
ECHO * * * * * * * * * * * * * *
ECHO.
ECHO.
ECHO.
ECHO.
ECHO Congratulations! You guessed it.
ECHO.
ECHO The number was %UserNumber%
ECHO.
ECHO You guessed it in %NoGuesses% guesses
ECHO.
ECHO. Number of High Guesses: %High%
ECHO.
ECHO Number of Low Guesses: %Low%
ECHO.
ECHO.
ECHO.
ECHO.
ECHO * * * * * * * * * * * * * *
ECHO.
ECHO.
ECHO.
ECHO.

PAUSE
 
This sounds awfully like a homework assignment... but....

At the beginning, before "Set RandomNo=%random%":
:BEGIN

At the very end (also delete the last pause):

ECHO Would you like to play again?
ECHO.
ECHO.
SET /P M=(y/n?):
IF %M%==y GOTO BEGIN
IF %M%==n exit
 
Thanks I really appreciate it, it is homework but the homework was getting the code to work orginally. The modifying was optional but I do appreciate it
 
Back
Top Bottom