2014-01-20 111 views
0

這是一個我的朋友爲了好玩而寫的腳本,有兩件事我不知道爲什麼它不起作用。一個問題12總是對的,不管輸入是什麼。另外,如果您通過調查問卷一路進入,它會自動選擇數字1,但我不確定原因。批量故障

關閉@echo 顏色0℃

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

set /p x=number如果您只是按回車鍵,則不會設置%x%。它只是讓%x%保持原樣。要更正它,請在set /p x=number之前添加set x=0。你也可以很容易地實現一些錯誤檢查(除了「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 

你也應該overthink的cls他們似乎使用是奇數的地方^^

通過糾正你的代碼,你會發現對自己Q12的行爲的原因 - 有缺少的東西

+0

謝謝,我會補充的我關閉你的建議並將代碼發回給我的朋友。 – imaginecode

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

+0

非常感謝,我的朋友會很高興得到它正常工作。 – imaginecode