2

每次我尝试播放时,它都会退出,而不是当我点击进入时移动到下一行;它工作正常,直到你输入你的名字,然后它跳到问题 1,然后它退出。我不是这方面的专家,所以我想知道我做错了什么以及如何解决它。如果您发现任何其他错误,请随时指出。谢谢!:)

@echo off
color F0
cls
echo.
echo True or False
pause
echo Welcome! May I ask your name before we begin?
echo.
set /p name=
echo.
echo Hello %name%, nice to meet you!
echo.
echo My name is Myst.
echo.
cls
echo.
echo Let us begin!
:start
color FC
cls
echo.
echo QUESTION 1
pause
echo.
echo Though hard, you can start a fire by rubbing 2 cool ranch
   doritos together  for a long time.
echo.
echo TRUE or FALSE
echo.
set /p variable=
echo.
if %variable% equ TRUE goto question2 if %variable% equ FALSE goto
   answer1
if %variable% neq TRUE goto start
:answer1
cls
echo.
echo Wrong! Though it is very hard, it is possible.
goto start
:question2
color F3
cls
echo QUESTION 2
pause
echo.
echo Singing in the shower lowers your cholesterol, heart rate, &
   risk of cancer  and heart disease.
echo.
echo TRUE or FALSE
echo.
set /p variable=
echo.
if %variable% equ TRUE goto answer2
if %variable% equ FALSE goto question3
if %variable% neq TRUE goto question2
:answer2
cls
echo.
echo Wrong!
echo.
echo Here is a fast fact for you %name%. Dark chocolate doesn't
   either.
goto start
:question3
color F5
cls
echo QUESTION 3
pause
echo.
exit
4

3 回答 3

2

您遇到了一些语法错误和各种问题。试试这个作为示例:它进行了一些更改和编辑以使其更加健壮。

@echo off
color F0
cls
echo.
echo True or False
echo.
set /p "name=Welcome! May I ask your name before we begin? "
echo.
echo Hello %name%, nice to meet you!
echo.
echo My name is Myst.
echo.
echo.
ping -n 3 localhost >nul
echo Let us begin!
pause
:start
color FC
cls
echo.
echo QUESTION 1
echo.
echo Though hard, you can start a fire by rubbing 2 cool ranch
echo doritos together for a long time.
echo.
echo. 
set /p "variable=TRUE or FALSE: "
echo.
if /i "%variable%" equ "TRUE" (
echo Right!
pause
goto :question2
)
cls
echo.
echo Wrong! Though it is very hard, it is possible.
pause
:question2
color F3
cls
echo QUESTION 2
echo.
echo Singing in the shower lowers your cholesterol, heart rate, &
echo risk of cancer and heart disease.
echo.
set /p "variable=TRUE or FALSE: "
echo.
if /i "%variable%" equ "FALSE" (
echo Right!
pause
goto :question3
)
echo 
cls
echo.
echo Wrong!
echo.
echo Here is a fast fact for you %name%. Dark chocolate doesn't
echo either.
pause
:question3
color F5
cls
echo QUESTION 3
pause
echo.
exit
于 2013-04-22T05:23:11.373 回答
2

尝试这个:

if "%variable%" equ "TRUE" goto :question2
if "%variable%" equ "FALSE" goto :answer1
goto :start
于 2013-04-22T04:31:20.960 回答
1
echo Hello %name%, nice to meet you!
echo.
echo My name is Myst.
echo.

cls

echo.
echo Let us begin!

The CLS command makes to clean the window, so you can read nothing. Also you need to stop the execution of the script (with a pause).

You are using the cls command too many times without pausing the code.

Also you need to try to don't make a intelligible code like that, you need to make indentations, make empty lines, to let us understand the code.

And no need to use string recognitions like "true or false?" because exist a type of variable called "Boolean" and that is only True/False, you can use boolean questions with the Choice command.

Really you need to rewrite it all the code again because you can see things like this:

if %variable% equ TRUE goto answer2
if %variable% equ FALSE goto question3
if %variable% neq TRUE goto question2

if variable only can be "true" and "False" then the third conditional never will be processed, no need to be a pro to understand it, is logical.

And think about what happens if the user type "true" or "TrUe" or any variant?

Then you will need to use the /I parameter of "IF" statement.

If /I EQU "True" (Goto...) ELSE (Goto...)

And you are using the operator "&" to print a string using echo command, but you can't print operators without using double-quoues or escaping the character:

Echo "&"
Echo ^&

Too many thing more for explain but the big problem of your code is that you've missed like 10 "pause" needed to read the strings.

PS: Sorry for my english.

Here is the corrected code:

@Echo off
Color F0

Echo+
Echo: True or False | MORE
Pause & CLS

Echo+
Echo: Welcome! May I ask your name before we begin? | MORE
set /p "name=" & CLS

Echo+
Echo: Hello %name%, nice to meet you! | MORE
Echo: My name is Myst.                | MORE
Pause & CLS

Echo+
Echo: Let us begin!
Pause & CLS

:start
color FC
Echo+
Echo: QUESTION 1
Pause
Echo+
Echo: TRUE or FALSE | MORE
Choice /C TF /M "Though hard, you can start a fire by rubbing 2 cool ranch doritos together for a long time."
if %ERRORLEVEL% EQU 1 (Goto Question2) ELSE (goto Answer1)

:answer1
cls
Echo+
Echo: Wrong! Though it is very hard, it is possible.
Pause & CLS
Goto :start

:question2
color F3
cls
Echo: QUESTION 2
pause
Echo+
Echo: TRUE or FALSE | MORE
Choice /C TF /M "Singing in the shower lowers your cholesterol, heart rate, & risk of cancer and heart disease."
if %ERRORLEVEL% EQU 1 (Goto answer2) ELSE (goto question3)

:answer2
cls
Echo+
Echo: Wrong! | MORE
Echo: Here is a fast fact for you %name%. Dark chocolate doesn't either.
Pause & CLS
goto start

:question3
...
...
...
于 2013-04-22T04:43:06.627 回答