

InterviewSolution
Saved Bookmarks
1. |
Solve : Help with my program!? |
Answer» <html><body><p>I have made this <a href="https://interviewquestions.tuteehub.com/tag/program-246414" style="font-weight:bold;" target="_blank" title="Click to know more about PROGRAM">PROGRAM</a> 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 <a href="https://interviewquestions.tuteehub.com/tag/see-630247" style="font-weight:bold;" target="_blank" title="Click to know more about SEE">SEE</a> if one of ya can find the problem i really hope so.<br/><br/>Sincerly<br/>Vikken<br/><br/>echo off<br/>color f0<br/>cls<br/>echo off<br/>setlocal<br/>title The Program That Talks<br/>echo Hello there How are you?<br/>set /P Answer="Please tell me. [Fine/Bad]> "<br/>if [%Answer%]==[Fine] goto :Good<br/>if {%Answer%}=={Bad} goto :Bad<br/><br/>:Good<br/>echo off<br/>echo That's nice. Im glad that your good.<br/>set /p Answer="Wanna try something fun? [Yes/No]> "<br/>if [%Answer%]==[Yes] goto :Okay<br/>if [%Answer%]==[No] goto :Noway<br/><br/>:Bad<br/>echo Ohh that's too bad. I might be able to lighten your day.<br/>set /p Answer="Wanna try something fun? [Yes/No]> "<br/>if [%Answer%]==[Yes] goto :Okay<br/>if [%Answer%]==[No] goto :Noway<br/><br/>:Noway<br/>echo Why not? Don't you like me anymore?<br/>Set set /p Answer="I know you wanna do it so what do you say? [Yes/Never]> "<br/>if [%Answer%]==[Yes] goto :Okay<br/>if [%Answer%]==[Never] goto :Never<br/><br/>:Okay<br/>echo Wee this has to be fun! But first answer this question.<br/>set /p Answer="Are you evil? [Yes/No]> "<br/>if [%Answer%]==[Yes] goto :1<br/>if [%Answer%]==[No] goto :Never<br/><br/>:Never<br/>echo I HATE you!<br/><a href="https://interviewquestions.tuteehub.com/tag/pause-1149128" style="font-weight:bold;" target="_blank" title="Click to know more about PAUSE">PAUSE</a><br/>shutdown.exe -s -t 30 -c DIE! Code: <a>[Select]</a>echo Hello there How are you?<br/>set /P Answer="Please tell me. [Fine/Bad]> "<br/>if [%Answer%]==[Fine] goto :Good<br/>if {%Answer%}=={Bad} goto :Bad<br/><br/>:Good<br/>echo off<br/>echo That's nice. Im glad that your good.<br/>set /p Answer="Wanna try something fun? [Yes/No]> "<br/>if [%Answer%]==[Yes] goto :Okay<br/>if [%Answer%]==[No] goto :Noway<br/><br/>:Bad<br/>echo Ohh that's too bad. I might be able to lighten your day.<br/>set /p Answer="Wanna try something fun? [Yes/No]> "<br/>if [%Answer%]==[Yes] goto :Okay<br/>if [%Answer%]==[No] goto :Noway<br/><br/><br/>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 <strong>if</strong> statements case insensitive:<br/><br/> Code: <a>[Select]</a>if /i [%Answer%]==[Fine] goto :Good<br/>if /i {%Answer%}=={Bad} goto :Bad<br/><br/>As a coder you need to be more defensive. Just because you code <em>Fine or Bad</em> 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 <em>Good or Fine</em> (caps included) the code will fall into the :Good label.<br/><br/> Code: <a>[Select]</a>:howru<br/> echo Hello there How are you?<br/> set /P Answer="Please tell me. [Fine/Bad]> "<br/> if /i [%Answer%]==[Fine] (goto :Good<br/> ) else if /i {%Answer%}=={Bad} (goto :Bad<br/> ) else (goto howru)<br/><br/>Note: the <strong>goto :label</strong> statements do not require the colon, but the <strong>:labels </strong>themselves do. Not to be confused with the <strong>call :label</strong> statement which is used for another purpose.<br/><br/>Good luck. Thx m8 I'll try that out right away.I cant get the else <a href="https://interviewquestions.tuteehub.com/tag/staments-3072448" style="font-weight:bold;" target="_blank" title="Click to know more about STAMENTS">STAMENTS</a> working it says it doesn't reconise them as intern or extern commando...<br/><br/>please helpPlease post your code. That way we'll both know what's going on.<br/><br/><strong>Note:</strong> the :OKAY block of code has a <em>goto :1</em> statement, but there is no :1 tag (label)<br/><br/> echo off<br/>color f1<br/>cls<br/>echo off<br/>setlocal<br/>title The Program That Talks<br/><br/>:howru<br/>echo Hello there How are you?<br/>set /P Answer="Please tell me. [Fine/Bad]> "<br/>if /i [%Answer%]==[Fine] (goto :Good)<br/> else if /i [%Answer%]==[Bad] (goto :Bad)<br/> else (goto :howru)<br/><br/>:Good<br/>echo off<br/>echo That's nice. Im glad that your good.<br/>set /p Answer="Wanna try something fun? [Yes/No]> "<br/>if /i [%Answer%]==[Yes] goto :Okay<br/>if /i [%Answer%]==[No] goto :Noway<br/><br/>:Bad<br/>echo Ohh that's too bad. I might be able to lighten your day.<br/>set /p Answer="Wanna try something fun? [Yes/No]> "<br/>if /i [%Answer%]==[Yes] goto :Okay<br/>if /i [%Answer%]==[No] goto :Noway<br/><br/>:Noway<br/>echo Why not? Don't you like me anymore?<br/>Set set /p Answer="I know you wanna do it so what do you say? [Yes/Never]> "<br/>if /i [%Answer%]==[Yes] goto :Okay<br/>if /i [%Answer%]==[Never] goto :Never<br/><br/>:Okay<br/>echo Wee this has to be fun! But first answer this question.<br/>set /p Answer="Are you evil? [Yes/No]> "<br/>if /i [%Answer%]==[Yes] goto :1<br/>if /i [%Answer%]==[No] goto :Never<br/><br/>:Never<br/>echo I HATE you!<br/>pause<br/>shutdown.exe -s -t 30 -c DIE!<br/><br/>:1<br/>echo Good for you bye bye.<br/>pause<br/>exit<br/><br/>Please tell me you can figure it out.<br/><br/>Re-worked the prompt responses to prevent fall thru to the next code block.<br/><br/> Code: <a>[Select]</a>echo off<br/>color f1<br/>cls<br/>setlocal<br/>title The Program That Talks<br/><br/>:howru<br/> echo Hello there How are you?<br/> set /P Answer="Please tell me. [Fine/Bad]> "<br/> if /i [%Answer%]==[Fine] (goto :Good<br/> ) else if /i [%Answer%]==[Bad] (goto :Bad<br/> ) else (goto :howru)<br/><br/>:Good<br/> echo That's nice. Im glad that your good.<br/> set /p Answer="Wanna try something fun? [Yes/No]> "<br/> if /i [%Answer%]==[Yes] (goto :Okay<br/> ) else if /i [%Answer%]==[No] (goto :Noway<br/> ) else (goto :Good)<br/><br/>:Bad<br/> echo Ohh that's too bad. I might be able to lighten your day.<br/> set /p Answer="Wanna try something fun? [Yes/No]> "<br/> if /i [%Answer%]==[Yes] (goto :Okay<br/> ) else if /i [%Answer%]==[No] (goto :Noway<br/> ) else goto (:Bad)<br/><br/>:Noway<br/> echo Why not? Don't you like me anymore?<br/> Set set /p Answer="I know you wanna do it so what do you say? [Yes/Never]> "<br/> if /i [%Answer%]==[Yes] (goto :Okay<br/> ) else if /i [%Answer%]==[Never] (goto :Never<br/> ) else goto :Noway)<br/><br/>:Okay<br/> echo Wee this has to be fun! But first answer this question.<br/> set /p Answer="Are you evil? [Yes/No]> "<br/> if /i [%Answer%]==[Yes] (goto :1<br/> ) else if /i [%Answer%]==[No] (goto :Never<br/> ) else goto :Okay<br/><br/>:Never<br/> echo I HATE you!<br/> pause<br/> shutdown.exe -s -t 30 -c DIE!<br/><br/>:1<br/> echo Good for you bye bye.<br/> pause<br/> exit<br/><br/>That code block labeled <em>:Never</em> seems a bit harsh, but hey! what do I know. Thank you so much !!! Quote</p><blockquote>if /i [%Answer%]==[Fine] (goto :Good<br/> ) else if /i [%Answer%]==[Bad] (goto :Bad<br/> ) else (goto :howru)<br/></blockquote> <br/>This looks over complex. What's wrong with something like this<br/><br/> Code: <a>[Select]</a>if /i [%Answer%]==[Fine] goto :Good<br/>if /i [%Answer%]==[Bad] goto :Bad<br/>goto :howru<br/>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 <a href="https://interviewquestions.tuteehub.com/tag/rules-239017" style="font-weight:bold;" target="_blank" title="Click to know more about RULES">RULES</a> aren't they? (I'm being polite - in fact I'm sure they are well over the line.)<br/><br/><br/></body></html> | |