Math Help

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
The Great One
Posts: 23
Joined: 02 Jan 2010 20:54

Math Help

#1 Post by The Great One » 15 Jan 2010 21:58

My code is set up as a simple test. I want to take the wrong answers and have the batch file calculate the score out of 100. Here is my code.

Code: Select all

@echo off
echo 1: Take Test
echo 2: Exit

set /p userinp=choose a number(1-2):
set userinp=%userinp:~0,1%
if "%userinp%"=="1" goto 1
if "%userinp%"=="2" goto exit

:1
cls
echo What is Avagrados Number?
echo.
echo 1: 6.2x10(32)
echo 2: 6.02x10(22)
echo 3: 6.02x10(23)
echo 4: 4.06x10923)

set /p userinp=choose a number(1-4):
set userinp=%userinp:~0,1%
if "%userinp%"=="1" goto wrong1
if "%userinp%"=="2" goto wrong2
if "%userinp%"=="3" goto right1
if "%userinp%"=="4" goto wrong3

:wrong1
cls
echo Incorrect
pause
goto 2

:wrong2
cls
echo Incorrect
pause
goto 2

:Wrong3
cls
echo Incorrect
pause
goto 2

:right1
cls
echo Correct
pause
goto 2

:2
cls
Echo What is the formula for density?
Echo.
echo 1:D=M/V
echo 2:D=V/M
echo 3:R=T/V
echo 4:T=D/V

set /p userinp=choose a number(1-4):
set userinp=%userinp:~0,1%
if "%userinp%"=="1" goto right1-1
if "%userinp%"=="2" goto wrong1-1
if "%userinp%"=="3" goto wrong2-1
if "%userinp%"=="4" goto wrong3-1

:wrong1-1
cls
echo Incorrect
pause
goto 3

:wrong2-1
cls
echo Incorrect
pause
goto 3

:Wrong3-1
cls
echo Incorrect
pause
goto 3

:right1-1
cls
echo Correct
pause
goto 3

:3
cls
Echo What Type of Reaction is this? 
echo "AB+CD--->AD+CB"
Echo.
echo 1: Single Replacement
echo 2: Double Replacement
echo 3: Synthesis
echo 4: Combustion
echo 5: Decomposition

set /p userinp=choose a number(1-5):
set userinp=%userinp:~0,1%
if "%userinp%"=="1" goto wrong1-2
if "%userinp%"=="2" goto right1-2
if "%userinp%"=="3" goto wrong2-2
if "%userinp%"=="4" goto wrong3-2
if "%userinp%"=="5" goto wrong4-2

:wrong1-2
cls
echo Incorrect
pause
goto 4

:wrong2-2
cls
echo Incorrect
pause
goto 4

:Wrong3-2
cls
echo Incorrect
pause
goto 4

:Wrong4-2
cls
echo Incorrect
pause
goto 4

:right1-2
cls
echo Correct
pause
goto 4

:4
cls
Echo What is an Emperical Formula?
Echo.
echo 1: The Complete formula with all the correct subscripts
echo 2: A Balanced Equasion
echo 3: The shortest formula for an equasion
echo 4: An equasion with only the coefficients


set /p userinp=choose a number(1-4):
set userinp=%userinp:~0,1%
if "%userinp%"=="1" goto wrong1-3
if "%userinp%"=="2" goto wrong1-3
if "%userinp%"=="3" goto right1-3
if "%userinp%"=="4" goto wrong1-3

:wrong1-3
cls
echo Incorrect
pause
goto 5

:right1-3
cls
echo Correct
pause
goto 5

:5
cls
Echo What is not a property for a non-metal?
Echo.
echo 1: Bad at conducting Heat
echo 2: Bad at conduction electricty
echo 3: Brittle
echo 4: Reflect light well


set /p userinp=choose a number(1-4):
set userinp=%userinp:~0,1%
if "%userinp%"=="1" goto wrong1-4
if "%userinp%"=="2" goto wrong1-4
if "%userinp%"=="3" goto wrong1-4
if "%userinp%"=="4" goto right1-4

:wrong1-4
cls
echo Incorrect
pause
goto 6

:right1-4
cls
echo Correct
pause
goto 6

:6
cls
Echo What does boyles law state?
Echo.
echo 1: Pressure and temperature are inversely proportional
echo 2: Pressure and Volume are inveresly proportional at changing temperatures
echo 3: Pressure and Volume are inveresly proportional at a constant temperature
echo 4: Pressure and temperature are directly proportional


set /p userinp=choose a number(1-4):
set userinp=%userinp:~0,1%
if "%userinp%"=="1" goto wrong1-5
if "%userinp%"=="2" goto wrong1-5
if "%userinp%"=="3" goto right1-5
if "%userinp%"=="4" goto wrong1-5

:wrong1-5
cls
echo Incorrect
pause
goto 7

:right1-5
cls
echo Correct
pause
goto 7

:7
cls
Echo How do you get from grams of a compound to moles?
Echo.
echo 1: Grams of a compound / The molecular weight
echo 2: The molecular weight / Grams of a compound
echo 3: Grams of a compound X 6.02x10(23)
echo 4: Grams of a compound X the # of subscripts

set /p userinp=choose a number(1-4):
set userinp=%userinp:~0,1%
if "%userinp%"=="1" goto right1-6
if "%userinp%"=="2" goto wrong1-6
if "%userinp%"=="3" goto wrong1-6
if "%userinp%"=="4" goto wrong1-6

:wrong1-6
cls
echo Incorrect
pause
goto 8

:right1-6
cls
echo Correct
pause
goto 8

:8
cls
Echo What is a Polymer?
Echo.
echo 1: A combination of different nonrepeating elements
echo 2: A set of parentheses that are placed around the repeating units
echo 3: A string of molecules chemically combined
echo 4: A oxygen atom combined with a hydrogen atom

set /p userinp=choose a number(1-4):
set userinp=%userinp:~0,1%
if "%userinp%"=="1" goto wrong1-7
if "%userinp%"=="2" goto right1-7
if "%userinp%"=="3" goto wrong1-7
if "%userinp%"=="4" goto wrong1-7

:wrong1-7
cls
echo Incorrect
pause
goto 9

:right1-7
cls
echo Correct
pause
goto 9

:9
cls
Echo Which one of these units are in stp?
Echo.
echo 1: 14.2 psi
echo 2: 101.31 K pascal
echo 3: 2 atm
echo 4: 750mm of hg

set /p userinp=choose a number(1-4):
set userinp=%userinp:~0,1%
if "%userinp%"=="1" goto wrong1-8
if "%userinp%"=="2" goto right1-8
if "%userinp%"=="3" goto wrong1-8
if "%userinp%"=="4" goto wrong1-8

:wrong1-8
cls
echo Incorrect
pause
goto 10

:right1-8
cls
echo Correct
pause
goto 10

:10
cls
Echo In Pv=NRT, What does R stand for?
Echo.
echo 1: Rate
echo 2: .472
echo 3: 100
echo 4: .082

set /p userinp=choose a number(1-4):
set userinp=%userinp:~0,1%
if "%userinp%"=="1" goto wrong1-8
if "%userinp%"=="2" goto wrong1-8
if "%userinp%"=="3" goto wrong1-8
if "%userinp%"=="4" goto right1-8

:wrong1-9
cls
echo Incorrect
pause
goto %cal

:right1-9
cls
echo Correct
pause
goto %cal

:%cal





:exit
exit

DosItHelp
Expert
Posts: 239
Joined: 18 Feb 2006 19:54

#2 Post by DosItHelp » 16 Jan 2010 01:07

Hey The Great One,

I simplified your batch a little and added the percentage-correct at the end.

Code: Select all

@echo off
set /a right=0, wrong=0

echo 1: Take Test
echo 2: Exit

set /p userinp=choose a number(1-2):
set userinp=%userinp:~0,1%
if "%userinp%"=="2" GOTO:EOF


cls
echo What is Avagrados Number?
echo.
echo 1: 6.2x10(32)
echo 2: 6.02x10(22)
echo 3: 6.02x10(23)
echo 4: 4.06x10923)
set /p userinp=choose a number(1-4):
call:check %userinp:~0,1% 3

cls
Echo What is the formula for density?
Echo.
echo 1:D=M/V
echo 2:D=V/M
echo 3:R=T/V
echo 4:T=D/V
set /p userinp=choose a number(1-4):
call:check %userinp:~0,1% 1

cls
Echo What Type of Reaction is this?
echo "AB+CD--->AD+CB"
Echo.
echo 1: Single Replacement
echo 2: Double Replacement
echo 3: Synthesis
echo 4: Combustion
echo 5: Decomposition
set /p userinp=choose a number(1-5):
call:check %userinp:~0,1% 2

cls
Echo What is an Emperical Formula?
Echo.
echo 1: The Complete formula with all the correct subscripts
echo 2: A Balanced Equasion
echo 3: The shortest formula for an equasion
echo 4: An equasion with only the coefficients
set /p userinp=choose a number(1-4):
call:check %userinp:~0,1% 3

cls
Echo What is not a property for a non-metal?
Echo.
echo 1: Bad at conducting Heat
echo 2: Bad at conduction electricty
echo 3: Brittle
echo 4: Reflect light well
set /p userinp=choose a number(1-4):
call:check %userinp:~0,1% 4

cls
Echo What does boyles law state?
Echo.
echo 1: Pressure and temperature are inversely proportional
echo 2: Pressure and Volume are inveresly proportional at changing temperatures
echo 3: Pressure and Volume are inveresly proportional at a constant temperature
echo 4: Pressure and temperature are directly proportional
set /p userinp=choose a number(1-4):
call:check %userinp:~0,1% 3

cls
Echo How do you get from grams of a compound to moles?
Echo.
echo 1: Grams of a compound / The molecular weight
echo 2: The molecular weight / Grams of a compound
echo 3: Grams of a compound X 6.02x10(23)
echo 4: Grams of a compound X the # of subscripts
set /p userinp=choose a number(1-4):
call:check %userinp:~0,1% 1

cls
Echo What is a Polymer?
Echo.
echo 1: A combination of different nonrepeating elements
echo 2: A set of parentheses that are placed around the repeating units
echo 3: A string of molecules chemically combined
echo 4: A oxygen atom combined with a hydrogen atom
set /p userinp=choose a number(1-4):
call:check %userinp:~0,1% 2

cls
Echo Which one of these units are in stp?
Echo.
echo 1: 14.2 psi
echo 2: 101.31 K pascal
echo 3: 2 atm
echo 4: 750mm of hg
set /p userinp=choose a number(1-4):
call:check %userinp:~0,1% 2

cls
Echo In Pv=NRT, What does R stand for?
Echo.
echo 1: Rate
echo 2: .472
echo 3: 100
echo 4: .082
set /p userinp=choose a number(1-4):
call:check %userinp:~0,1% 4

set /a result=100*right/(right+wrong)
echo.
echo Percent correct: %result%%%

GOTO:EOF

:check
echo.
if "%~1"=="%~2" (
    set /a right+=1
    echo.Correct!
) else (
    set /a wrong+=1
    echo.Incorrect.
)
echo.
pause
GOTO:EOF


DosItHelp? :wink:

The Great One
Posts: 23
Joined: 02 Jan 2010 20:54

#3 Post by The Great One » 16 Jan 2010 14:57

Thanks for the Help :)

Post Reply