1.

Solve : Help with my program!?

Answer»

I have made this PROGRAM but i have a major problem. When i run the program and try to make it act on the answers i've inserted it just takes it from the top it doesn't jump to the ":nametag" i've made. Please try it and SEE if one of ya can find the problem i really hope so.

Sincerly
Vikken

echo off
color f0
cls
echo off
setlocal
title The Program That Talks
echo Hello there How are you?
set /P Answer="Please tell me. [Fine/Bad]> "
if [%Answer%]==[Fine] goto :Good
if {%Answer%}=={Bad} goto :Bad

:Good
echo off
echo That's nice. Im glad that your good.
set /p Answer="Wanna try something fun? [Yes/No]> "
if [%Answer%]==[Yes] goto :Okay
if [%Answer%]==[No] goto :Noway

:Bad
echo Ohh that's too bad. I might be able to lighten your day.
set /p Answer="Wanna try something fun? [Yes/No]> "
if [%Answer%]==[Yes] goto :Okay
if [%Answer%]==[No] goto :Noway

:Noway
echo Why not? Don't you like me anymore?
Set set /p Answer="I know you wanna do it so what do you say? [Yes/Never]> "
if [%Answer%]==[Yes] goto :Okay
if [%Answer%]==[Never] goto :Never

:Okay
echo Wee this has to be fun! But first answer this question.
set /p Answer="Are you evil? [Yes/No]> "
if [%Answer%]==[Yes] goto :1
if [%Answer%]==[No] goto :Never

:Never
echo I HATE you!
PAUSE
shutdown.exe -s -t 30 -c DIE! Code: [Select]echo Hello there How are you?
set /P Answer="Please tell me. [Fine/Bad]> "
if [%Answer%]==[Fine] goto :Good
if {%Answer%}=={Bad} goto :Bad

:Good
echo off
echo That's nice. Im glad that your good.
set /p Answer="Wanna try something fun? [Yes/No]> "
if [%Answer%]==[Yes] goto :Okay
if [%Answer%]==[No] goto :Noway

:Bad
echo Ohh that's too bad. I might be able to lighten your day.
set /p Answer="Wanna try something fun? [Yes/No]> "
if [%Answer%]==[Yes] goto :Okay
if [%Answer%]==[No] goto :Noway


You are requiring too much from the user. The first question requires a Fine/Bad response (caps included). A better approach would be to make the if statements case insensitive:

Code: [Select]if /i [%Answer%]==[Fine] goto :Good
if /i {%Answer%}=={Bad} goto :Bad

As a coder you need to be more defensive. Just because you code Fine or Bad as the correct response, there is no guarantee the user will actually pick one of them. You must be prepared for any response otherwise the code will fall through to the next instruction which is probably not what you want. In the original code, if the user enters neither Good or Fine (caps included) the code will fall into the :Good label.

Code: [Select]:howru
  echo Hello there How are you?
  set /P Answer="Please tell me. [Fine/Bad]> "
  if /i [%Answer%]==[Fine] (goto :Good
    ) else if /i {%Answer%}=={Bad} (goto :Bad
    ) else (goto howru)

Note: the goto :label statements do not require the colon, but the :labels themselves do.  Not to be confused with the call :label statement which is used for another purpose.

Good luck.  Thx m8 I'll try that out right away.I cant get the else STAMENTS working it says it doesn't reconise them as intern or extern commando...

please helpPlease post your code. That way we'll both know what's going on.

Note: the :OKAY block of code has a goto :1 statement, but there is no :1 tag (label)

 echo off
color f1
cls
echo off
setlocal
title The Program That Talks

:howru
echo Hello there How are you?
set /P Answer="Please tell me. [Fine/Bad]> "
if /i [%Answer%]==[Fine] (goto :Good)
 else if /i [%Answer%]==[Bad] (goto :Bad)
 else (goto :howru)

:Good
echo off
echo That's nice. Im glad that your good.
set /p Answer="Wanna try something fun? [Yes/No]> "
if /i [%Answer%]==[Yes] goto :Okay
if /i [%Answer%]==[No] goto :Noway

:Bad
echo Ohh that's too bad. I might be able to lighten your day.
set /p Answer="Wanna try something fun? [Yes/No]> "
if /i [%Answer%]==[Yes] goto :Okay
if /i [%Answer%]==[No] goto :Noway

:Noway
echo Why not? Don't you like me anymore?
Set set /p Answer="I know you wanna do it so what do you say? [Yes/Never]> "
if /i [%Answer%]==[Yes] goto :Okay
if /i [%Answer%]==[Never] goto :Never

:Okay
echo Wee this has to be fun! But first answer this question.
set /p Answer="Are you evil? [Yes/No]> "
if /i [%Answer%]==[Yes] goto :1
if /i [%Answer%]==[No] goto :Never

:Never
echo I HATE you!
pause
shutdown.exe -s -t 30 -c DIE!

:1
echo Good for you bye bye.
pause
exit

Please tell me you can figure it out.

Re-worked the prompt responses to prevent fall thru to the next code block.

Code: [Select]echo off
color f1
cls
setlocal
title The Program That Talks

:howru
  echo Hello there How are you?
  set /P Answer="Please tell me. [Fine/Bad]> "
  if /i [%Answer%]==[Fine] (goto :Good
    ) else if /i [%Answer%]==[Bad] (goto :Bad
    ) else (goto :howru)

:Good
  echo That's nice. Im glad that your good.
  set /p Answer="Wanna try something fun? [Yes/No]> "
  if /i [%Answer%]==[Yes] (goto :Okay
    ) else if /i [%Answer%]==[No] (goto :Noway
    ) else (goto :Good)

:Bad
  echo Ohh that's too bad. I might be able to lighten your day.
  set /p Answer="Wanna try something fun? [Yes/No]> "
  if /i [%Answer%]==[Yes] (goto :Okay
    ) else if /i [%Answer%]==[No] (goto :Noway
    ) else goto (:Bad)

:Noway
  echo Why not? Don't you like me anymore?
  Set set /p Answer="I know you wanna do it so what do you say? [Yes/Never]> "
  if /i [%Answer%]==[Yes] (goto :Okay
    ) else if /i [%Answer%]==[Never] (goto :Never
    ) else goto :Noway)

:Okay
  echo Wee this has to be fun! But first answer this question.
  set /p Answer="Are you evil? [Yes/No]> "
  if /i [%Answer%]==[Yes] (goto :1
    ) else if /i [%Answer%]==[No] (goto :Never
    ) else goto :Okay

:Never
  echo I HATE you!
  pause
  shutdown.exe -s -t 30 -c DIE!

:1
  echo Good for you bye bye.
  pause
  exit

That code block labeled :Never seems a bit harsh, but hey! what do I know.  Thank you so much !!! Quote

if /i [%Answer%]==[Fine] (goto :Good
    ) else if /i [%Answer%]==[Bad] (goto :Bad
    ) else (goto :howru)

This looks over complex. What's wrong with something like this

Code: [Select]if /i [%Answer%]==[Fine] goto :Good
if /i [%Answer%]==[Bad] goto :Bad
goto :howru
By the way, I am uneasy about that shutdown stuff at the end. Childish prank scripts that shut down other people's computers are kind of borderline in terms of the CH RULES aren't they? (I'm being polite - in fact I'm sure they are well over the line.)




Discussion

No Comment Found