这是我朋友写的一个有趣的剧本,有两件事我无法弄清楚为什么它不起作用。一个问题12号总是正确无论输入是什么。此外,如果您在问卷中一直按下输入,它会自动选择1号,我不知道为什么。
@echo off color 0c
title food quiz!
:begin
echo.
echo Hello! and welcome to the ...FOOD QUIZ...
echo.
echo To enter your answer, choose your answer, press space, then type the number
echo your answer was listed as and press enter.
pause.
cls
set score=0
:Q1
echo.
echo question 1
echo.
echo In which country did creme brulee originate?
echo.
echo 1. Italy
echo 2. Japan
echo 3. France
echo.
pause
set /p x=number
if %x%==1 goto A
if %x%==2 goto B
if %x%==3 goto C
:A
cls
echo.
echo Sorry!... creme brulee is a french dish.
pause
goto Q2
:B
cls
echo.
echo Sorry!... creme brulee is a french dish.
pause
goto Q2
:C
cls
echo.
echo Correct!
pause
set /a score=score+1
goto Q2
:Q2
cls
echo.
echo question 2
echo.
echo A waz wan is a celebratory ___ course meal from the Kashmir valley of india.
echo.
echo 1. 10
echo 2. 25
echo 3. 36
echo.
pause
cls
set /p x=number
if %x%==1 goto A1
if %x%==2 goto B1
if %x%==3 goto C1
:A1
cls
echo.
echo Sorry!... a waz wan is a 36 course meal. only for special occasions.
pause
cls
goto Q3
:B1
cls
echo.
echo Sorry!... a waz wan is a 36 course meal. only for special occasions.
pause
cls
goto Q3
:C1
cls
echo.
echo Yes! waz wans are only for special occasion.
pause
cls
set /a score=score+1
goto Q3
:Q3
cls
echo.
echo question 3
echo.
echo What is "chiqueti"? (pronounced chiketi)
echo.
echo 1. small gourmet snacks favored by the gondoleirs of venice.
echo 2. sausages from finland.
echo 3. small bite sized rolls served as streetfood in the phillipines.
echo.
pause
cls
set /p x=number
if %x%==1 goto A2
if %x%==2 goto B2
if %x%==3 goto C2
:A2
cls
echo.
echo Correct!
pause
cls
set /a score=score+1
goto Q4
:B2
cls
echo.
echo Nope! Chiqueti are small gourmet snacks favored by the gondoleirs of venice.
pause
cls
goto Q4
:C2
cls
echo.
echo Nope! Chiqueti are small gourmet snacks favored by the gondoleirs of venice.
pause
cls
goto Q4
:Q4
cls
echo.
echo question 4
echo.
echo Haggis is the national dish of which Country in the united Kingdom?
echo.
echo 1. England
echo 2. Scotland
echo 3. Wales
pause
cls
set /p x=number
if %x%==1 goto A3
if %x%==2 goto B3
if %x%==3 goto C3
:A3
cls
echo.
echo Incorrect! haggis is the national dish of scotland. haggis is the ground up
echo pluck of a sheep, mixed with oats and echo onions, then stuffed in a sheep stomach and steamed.
echo.
pause
cls
goto Q5
:B3
echo.
echo Yep! haggis is the ground up pluck of a sheep, mixed with oats and onions, then stuffed in a sheep stomach and steamed.
echo.
pause
cls
set /a score=score+1
goto Q5
:C3
cls
echo.
echo Incorrect! haggis is the national dish of scotland. haggis is the ground up
echo pluck of a sheep, mixed with oats and onions, then stuffed in a sheep stomach and steamed.
echo.
pause
cls
goto Q5
:Q5
cls
echo.
echo question 5
echo.
echo What is Borscht?
echo.
echo 1. an entree.
echo 2. a dessert.
echo 3. a soup like side dish.
echo.
pause
cls
set /p x=number
if %x%==1 goto A4
if %x%==2 goto B4
if %x%==3 goto c4
:A4
cls
echo.
echo Sorry! Borscht is a russian soup like side dish.
echo.
pause
cls
goto Q6
:B4
cls
echo.
echo Sorry! Borscht is a russian soup like side dish.
echo.
pause
cls
goto Q6
:C4
cls
echo.
echo Yes! Borscht is usually a liquidy vegetable puree, sometimes containing milk.
echo.
pause
cls
set /a score=score+1
goto Q6
:Q6
echo.
echo question 6
echo.
echo Bleenies (aka bleens) are a popular streetfood of which country?
echo.
echo 1. Norway
echo 2. Russia
echo 3. romania
echo.
pause
cls
set /p x=number
if %x%==1 goto A5
if %x%==2 goto B5
if %x%==3 goto C5
:A5
echo.
echo Incorrect! Bleenies are a popular streetfood of Russia.
echo.
pause
cls
goto Q7
:B5
echo.
echo Yes!
echo.
pause
cls
set /a score=score+1
goto Q7
:C5
echo.
echo Incorrect! Bleenies are a popular streetfood of Russia.
echo.
pause
cls
goto Q7
:Q7
echo.
echo question 7
echo.
echo Kahlia is a Moraccan dish...What is "kahlia"?
echo.
echo 1. Meat, preserved in its own fat.
echo 2. A type of lamb stew with dates.
echo 3. A tea containing cinnamon, reportedly an aphrodisiac.
echo.
pause
cls
set /p x=number
if %x%==1 goto A6
if %x%==2 goto B6
if %x%==3 goto C6
:A6
echo.
echo Yes! Kahlia can be cooked with eggs and served as a breakfast food.
echo.
pause
set /a score=score+1
cls
goto Q8
:B6
echo.
echo Sorry! Kahlia is meat preserved in fat.
echo.
pause
cls
goto Q8
:C6
echo.
echo Sorry! Kahlia is meat preserved in fat.
echo.
pause
cls
goto Q8
:Q8
echo.
echo question 8
echo.
echo Muktuk is eaten by the native people of Alaska. What is muktuk?
echo.
echo 1. Raw seal skin with a layer of blubber.
echo 2. Raw dolphin skin with a layer of blubber.
echo 3. Raw whale skin with a layer of blubber.
echo.
pause
cls
set /p x=number
if %x%==1 goto A7
if %x%==2 goto B7
if %x%==3 goto c7
:A7
echo.
echo Sorry! Muktuk is Raw whale skin with a layer of blubber.
echo.
pause
cls
goto Q9
:B7
echo.
echo Sorry! Muktuk is Raw whale skin with a layer of blubber.
echo.
pause
cls
goto Q9
:C7
echo.
echo Yep!
echo.
pause
set /a score=score+1
cls
goto Q9
:Q9
echo.
echo question 9
echo.
echo Muktuk can be used to make which native Alaskan delicacy?
echo.
echo 1. Lunuk.
echo 2. Tunuk.
echo 3. Dunuk.
echo.
pause
cls
set /p x=number
if %x%==1 goto A8
if %x%==2 goto B8
if %x%==3 goto C8
:A8
echo.
echo Nope! Muktuk is used to make Dunuk. Dunuk is a fermented whale oil used as a sauce for other whale products.
echo.
pause
cls
goto Q10
:B8
echo.
echo Nope! Muktuk is used to make Dunuk. Dunuk is a fermented whale oil used as a sauce for other whale products.
echo.
pause
cls
goto Q10
:C8
echo.
echo Yes! Dunuk is a fermented whale oil used as a dipping sauce for other whale products.
pause
set /a score=score+1
cls
goto Q10
:Q10
echo.
echo question 10
echo.
echo Kopi Luwak is which type of beverage?
echo.
echo 1. A Balinese broth made from rhino beetle larvae.
echo 2. A coffee made from digested coffe beans excreted from the wild civet cat.
echo 3. A cold smoothie like drink also made from muktuk.
echo.
pause
cls
set /p x=number
if %x%==1 goto A9
if %x%==2 goto B9
if %x%==3 goto C9
:A9
echo.
echo Incorrect! Kopi Luwak is a coffee made from digested and excreted coffee beans ingested by the civet cat.
echo.
pause
cls
goto Q11
:B9
echo.
echo Yes! Kopi Luwak is a coffee made from digested and excreted coffee beans ingested by the civet cat.
echo.
pause
set /a score=score+1
cls
goto Q11
:C9
echo.
echo Incorrect! Kopi Luwak is a coffee made from digested and excreted coffee beans ingested by the civet cat.
echo.
pause
cls
goto Q11
:Q11
echo.
echo question 11
echo.
echo What is "Hicarl"?
echo.
echo 1. fermented meat from the greenlandic shark.
echo 2. A Finish greeting used only to greet people named Carl.
echo 3. A native Maori pork dish.
echo.
pause
cls
if %x%==1 goto A10
if %x%==2 goto B10
if %x%==3 goto C10
:A10
echo.
echo Yes!
echo.
echo Hicarl is made in Iceland using the Greenlandic shark.
echo.
pause
set /a score=score+1
cls
goto Q12
:B10
echo.
echo No!
echo.
echo Hicarl is made in Iceland using the Greenlandic shark.
echo.
pause
cls
goto Q12
:C10
echo.
echo No!
echo.
echo Hicarl is made in Iceland using the Greenlandic shark.
echo.
pause
cls
goto Q12
:Q12
echo.
echo question 12
echo.
echo Where is it beleived that coffee originated?
echo.
echo 1. Ethiopia
echo 2. Hawaii
echo 3. Colombia
echo.
pause
cls
if %x%==1 goto A11
if %x%==2 goto B11
if %x%==3 goto C11
:A11
echo.
echo YES!
echo.
echo It is said that an Ethiopian herder observed that his goats became very frisky after eating the bean of the coffee tree.
echo.
pause
cls
set /a score=score+1
goto end
:B11
echo.
echo WRONG :(
echo.
echo It is said that an Ethiopian herder observed that his goats became very frisky after eating the bean of the coffee tree.
echo.
pause
cls
goto end
:C11
echo.
echo WRONG :(
echo.
echo It is said that an Ethiopian herder observed that his goats became very frisky after eating the bean of the coffee tree.
echo.
pause
cls
goto end
:end
echo Congrats! you have finished the food quiz!
echo -----------------
echo your score is %score%
echo -----------------
echo.
echo 1. Play again
echo 2. exit.
echo.
pause
cls
set /p x=number
if %x%==1 goto begin
if %x%==2 exit
答案 0 :(得分:0)
它不认为你在这段代码中选择了“1”:
:Q1
rem You need this:
cls
echo stuff
set /p x=
if %x% == ?? goto A1
rem And this:
goto Q1
:A1
这将阻止它形成A1。
对于Q12,你需要set /p x=
它不存在。 :)
修改:您可以使用set /a score+=1
而不是set /a score=score+1
。
答案 1 :(得分:0)
set /p x=number
将不会设置%x%。它只是留下%x%。要更正它,请在set x=0
之前添加set /p x=number
。您也可以轻松实现一些错误检查(“1”,“2”和“3”以外的答案
作为例子:
:Q2
echo Question and answers
set x=0
set /p x=number
if %x%==1 goto A2
if %x%==2 goto B2
if %x%==3 goto C2
echo "wrong input"
goto :Q1
你也应该过度考虑他们似乎在奇怪的地方使用cls
^^
通过更正您的代码,您将自己注意到Q12行为的原因 - 缺少某些内容。