2016-12-01 70 views
-1

我是新來的批次,主要用於這一個學校項目。我也是堆棧溢出的新手,所以我們將不勝感激。當我到達代碼中的「:MARK」時,我不斷收到錯誤消息「set/a unexpected was currently at this time」。我只想在這裏轉儲整個代碼,對不起,如果它很混亂。「set/a在這個時候是意外的」

@echo off 
color 7C 

:MAINMENU 
cls 
title Main Menu 
echo To start the quiz, type 1 
echo To view the accreditations, type 2 
echo To exit the Shop Quiz, type 3 
set/p menuselection= Make your selection: 
if %menuselection%==1 goto QUESTIONONE 
if %menuselection%==2 goto ACCREDITATION 
if %menuselection%==3 goto ENDPROGRAM 

:QUESTIONONE 
cls 
title Question One of Ten 
echo What do you do if there is an accident in the shop? 
echo. 
echo 1. Duck and cover your head to avoid injury 
echo 2. Immediately go tell the instructor 
echo 3. Walk it off 
echo 4. Help the person who got hurt and fix the problem 
echo. 
set/p aone= 
goto QUESTIONTWO 

:QUESTIONTWO 
cls 
title Question Two of Ten 
echo What attitude should you always have in the shop? 
echo. 
echo 1. Calm and careful 
echo 2. Focused on surroundings 
echo 3. Mischievous and goofy 
echo 4. Attentive and ready to avoid injury 
echo. 
set/p atwo= 
goto QUESTIONTHREE 

:QUESTIONTHREE 
cls 
title Question Three of Ten 
echo Which of the following is NOT allowed for dress in shop? 
echo. 
echo 1. Sandals 
echo 2. Tucked Loose clothing 
echo 3. Crocs 
echo 4. Eye Goggles 
echo. 
set/p athree= 
goto QUESTIONFOUR 

:QUESTIONFOUR 
cls 
title Question Four of Ten 
echo What list of items must you be able to locate in the shop? 
echo. 
echo 1. Wood, tool shelf, eye goggles, fire extinguishers, power buttons 
echo 2. Fire blankets, first aid kits, fire extinguishers, power buttons, eye goggles 
echo 3. Eyewash stations, first aid kits, fire extinguishers, fire blankets, power buttons 
echo 4. Eye goggles, fire blankets, tool shelf, fire extinguishers, power buttons 
echo. 
set/p afour= 
goto QUESTIONFIVE 

:QUESTIONFIVE 
cls 
title Question Five of Ten 
echo Which of these potential risks is caused by clutter and spills? 
echo. 
echo 1. Bumping into things 
echo 2. Unnecessary strain 
echo 3. The drill catching the stock and spinning it 
echo 4. Prevention of proper lifting techniques 
echo. 
set/p afive= 
goto QUESTIONSIX 

:QUESTIONSIX 
cls 
title Question Six of Ten 
echo Which of these IS an acceptable mental condition for shop work? 
echo. 
echo 1. Tired 
echo 2. Hesitant 
echo 3. Rushed 
echo 4. Under the influence 
echo. 
set/p asix= 
goto QUESTIONSEVEN 

:QUESTIONSEVEN 
cls 
title Question Seven of Ten 
echo Your work station should NOT be: 
echo. 
echo 1. Adequately ventilated 
echo 2. Well-organized 
echo 3. Compact 
echo 4. Well-lit 
echo. 
set/p aseven= 
goto QUESTIONEIGHT 

:QUESTIONEIGHT 
cls 
title Question Eight of Ten 
echo What tool should you use to secure your work? 
echo. 
echo 1. Wrench 
echo 2. Paper weight 
echo 3. Vice 
echo 4. Your hand 
echo. 
set/p aeight= 
goto QUESTIONNINE 

:QUESTIONNINE 
cls 
title Question Nine of Ten 
echo What can you use to hold onto things like nails, screws, or chisels? 
echo. 
echo 1. Pocket 
echo 2. Hands 
echo 3. Mouth 
echo 4. All of the above 
echo. 
set/p anine= 
goto QUESTIONTEN 

:QUESTIONTEN 
cls 
title Question Ten of Ten 
echo Of the following only one action is acceptable. Select it. 
echo. 
echo 1. Using files without handles 
echo 2. Prying with a chisel 
echo 3. Using clamps that are really big 
echo 4. Hammering with a wrench 
echo. 
set/p athree= 
goto RESULTS 

:RESULTS 
cls 
title Results 
goto MARK 

:RESULTONE 
echo Question one of ten 
echo What do you do if there is an accident in the shop? 
if %aone%==1 echo "Duck and cover your head to avoid injury" is wrong. 
if %aone%==1 echo Correct answer is 2, "Immediately go tell the instructor" 
if %aone%==2 echo "Immediately go tell the instructor" is correct. 
if %aone%==3 echo "Walk it off" is wrong. 
if %aone%==3 echo Correct answer is 2, "Immediately go tell the instructor" 
if %aone%==4 echo "Help the person who got hurt and fix the problem" is wrong. 
if %aone%==4 echo Correct answer is 2, "Immediately go tell the instructor" 
pause 
goto RESULTTWO 

:RESULTTWO 
echo Question two of ten 
echo What attitude should you always have in shop? 
if %atwo%==1 echo "Calm and careful" is correct. 
if %atwo%==2 echo "Focused on surroungings" is wrong. 
if %atwo%==2 echo Correct answer is 1, "Calm and careful" 
if %atwo%==3 echo "Mischievous" is wrong. 
if %atwo%==3 echo Correct answer is 1, "Calm and careful" 
if %atwo%==4 echo "Attentive and ready to avoid" is wrong. 
if %atwo%==4 echo Correct answer is 1, "Calm and careful" 
pause 
goto RESULTTHREE 

:RESULTTHREE 
echo Question three of ten 
echo Which of the following is NOT allowed for dress in shop? 
if %athree%==1 echo "Sandals" is correct. 
if %athree%==2 echo "Tucked loose clothing" is wrong. 
if %athree%==2 echo Correct answer is 1, "Sandals" 
if %athree%==3 echo "Crocs" is wrong. 
if %athree%==3 echo Correct answer is 1, "Sandals" 
if %athree%==4 echo "Eye goggles" is wrong. 
if %athree%==4 echo Correct answer is 1, "Sandals" 
pause 
goto RESULTFOUR 

:RESULTFOUR 
echo Question four of ten 
echo What list of items must you be able to locate in the shop? 
if %afour%==1 echo "Wood, tool shelf, eye goggles, fire extinguishers, power buttons" is wrong. 
if %afour%==1 echo Correct answer is 3, "Eyewash stations, first aid kits, fire extinguishers, fire blankets, power buttons" 
if %afour%==2 echo "Fire blankets, first aid kits, fire extinguishers, power buttons" is wrong. 
if %afour%==2 echo Correct answer is 3, "Eyewash stations, first aid kits, fire extinguishers, fire blankets, power buttons" 
if %afour%==3 echo "Eyewash stations, first aid kits, fire extinguishers, fire blankets, power buttons" is correct. 
if %afour%==4 echo "Eye goggles, fire blankets, tool shelf, fire extinguishers, power buttons" is wrong. 
if %afour%==4 echo Correct answer is 3, "Eyewash stations, first aid kits, fire extinguishers, fire blankets, power buttons" 
pause 
goto RESULTFIVE 

:RESULTFIVE 
echo Question five of ten 
echo Which of these potential risks is caused by clutter and spills 
if %afive%==1 echo "Bumping into things" is correct. 
if %afive%==2 echo "Unnecessary strain" is wrong. 
if %afive%==2 echo Correct answer is 1, "Bumping into things" 
if %afive%==3 echo "The drill catching the stock and spinning it" is wrong. 
if %afive%==3 echo Correct answer is 1, "Bumping into things" 
if %afive%==4 echo "Prevention of proper lifting techniques" is wrong. 
if %afive%==4 echo Correct answer is 1, "Bumping into things" 
pause 
goto RESULTSIX 

:RESULTSIX 
echo Question six of ten 
echo Which of these is an acceptable mental condition for shop work? 
if %asix%==1 echo "Tired" is wrong. 
if %asix%==1 echo Correct answer is 2, "Hesitant" 
if %asix%==2 echo "Hesitant" is correct. 
if %asix%==3 echo "Rushed" is wrong. 
if %asix%==3 echo Correct answer is 2, "Hesitant" 
if %asix%==4 echo "Under the influence" is wrong. 
if %asix%==4 echo Correct answer is 2, "Hesitant" 
pause 
goto RESULTSEVEN 

:RESULTSEVEN 
echo Question seven of ten 
echo Your work station should NOT be: 
if %aseven%==1 echo "Adequately ventilated" is wrong. 
if %aseven%==1 echo Correct answer is 3, "Compact" 
if %aseven%==2 echo "Well-organized" is wrong. 
if %aseven%==2 echo Correct answer is 3, "Compact" 
if %aseven%==3 echo "Compact" is correct. 
if %aseven%==4 echo "Well-lit" is wrong. 
if %aseven%==4 echo Correct answer is 3, "Compact" 
pause 
goto RESULTEIGHT 

:RESULTEIGHT 
echo Question eight of ten 
echo What tool should you use to secure your work? 
if %aeight%==1 echo "Wrench" is wrong. 
if %aeight%==1 echo Correct answer is 3, "Vice" 
if %aeight%==2 echo "Paper weight" is wrong. 
if %aeight%==2 echo Correct answer is 3, "Vice" 
if %aeight%==3 echo "Vice" is correct. 
if %aeight%==4 echo "Your hand" is wrong. 
if %aeight%==4 echo Correct answer is 3, "Vice" 
pause 
goto RESULTNINE 

:RESULTNINE 
echo Question nine of ten 
echo What can you use to hold onto things like nails, screws, or chisels? 
if %anine%==1 echo "Pocket" is wrong. 
if %anine%==1 echo Correct answer is 2, "Hands" 
if %anine%==2 echo "Hands" is correct. 
if %anine%==3 echo "Mouth" is wrong. 
if %anine%==3 echo Correct answer is 2, "Hands" 
if %anine%==4 echo "All of the above" is wrong. 
if %anine%==4 echo Correct answer is 2, "Hands" 
pause 
goto RESULTTEN 

:RESULTTEN 
echo Question ten of ten 
echo Of the following only one action is acceptable. Select it. 
if %aten%==1 echo "Using files without handles" is wrong. 
if %aten%==1 echo Correct answer is 3, "Using clamps that are really big" 
if %aten%==2 echo "Prying with a chisel" is wrong. 
if %aten%==2 echo Correct answer is 3, "Using clamps that are really big" 
if %aten%==3 echo "Using clamps that are really big" is correct. 
if %aten%==4 echo "Hammering with a wrench" is wrong. 
if %aten%==4 echo Correct answer is 3, "Using clamps that are really big"" 
pause 
goto MAINMENU 

:MARK 
set mark= 0 
if %aone%==2 set/a mark="%mark%+1" 
if %atwo%==1 set/a mark="%mark%+1" 
if %athree%==1 set/a mark="%mark%+1" 
if %afour%==3 set/a mark="%mark%+1" 
if %afive%==1 set/a mark="%mark%+1" 
if %asix%==2 set/a mark="%mark%+1" 
if %aseven%==3 set/a mark="%mark%+1" 
if %aeight%==3 set/a mark="%mark%+1" 
if %anine%==2 set/a mark="%mark%+1" 
if %aten%==3 set/a mark="%mark%+1" 
echo %mark%"/10" questions correct. 
echo. 
echo To see your answers, type 1 
echo To go to the main menu, type 2 
echo To exit the quiz, type 3 
set/p markselection= Make your selection: 
if %markselection%==1 goto RESULTONE 
if %markselection%==2 goto MAINMENU 
if %markselection%==3 goto ENDPROGRAM 

:ACCREDITATION 
cls 
title Accreditation 
echo -Information taken from Grade 9 shop question booklet 
echo -Software used: Zed (available on chrome web store), 
echo Notepad++ (available by google search), 
echo Google drive and related services (available online) 
echo -Creator: Exalor Stepaniuk (shop class grade censored, 2016/17) 
echo. 
pause 
goto MAINMENU 

:ENDPROGRAM 
exit 

再一次,對不起,如果我通過在這裏轉儲整個腳本做錯了。我只是不知道自己在做什麼。

+0

正如你可以看到從SO代碼着色你有一個額外的「有 –

+0

@SamiKuhmonen好的漁獲!是在':RESULTTEN'後最後一個if語句有一個雙引號太多...有沒有一種方法手動打開和關閉着色?我只是在這裏有黑色腳本... – geisterfurz007

+0

@Exalor嗯...通常只有粘貼一個[mvce]在這裏更有意義,但我想在這種情況下,這是好的:)歡迎來到StackOverflow,並在[遊覽]看看網站的概念和徽章免費; – geisterfurz007

回答

1

你的錯誤的根本原因是這一行QUESTIONTEN

set/p athree= 

這看起來像一個錯字你的意思是設置aten,而不是athree

更具體地說,由於aten是空的,內MARK,比較最終被這樣解釋:

if ==3 set/a mark="[mark value]+1" 

注意,左操作數是空的。該行被解釋爲錯誤,這就是爲什麼你會收到錯誤。將athree更改爲aten可以解決此問題,但有一個技巧可以修復比較,以便在其中一個操作數爲空時不會中斷腳本。只要把東西放在雙方。例如,用引號括住比較器。

if "%leftoperand%"=="%rightoperand%" ... 

然後,即使其中一個或兩個都爲空,它也不會終止您的腳本。它看起來像if ""==""

此外,調試批處理文件的一般技巧是通過在關鍵位置放置echo語句(即使是簡單的語句,如echo 1)來縮小發生錯誤的位置(以及爲什麼)。然後,當您在輸出中看到1時,您知道該行已執行,並且您的錯誤在該行之後。一旦發現腳本終止的壞行,您可以回顯腳本的副本以查看腳本將其解釋爲什麼,這將幫助您找出問題所在。

像這樣:

echo if %aten%==3 set/a mark="%mark%+1" 
if %aten%==3 set/a mark="%mark%+1" 

我希望幫助。

+0

謝謝,我修好了。 – soja

相關問題