Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- REM Defines the variables 'change' and 'count'
- @echo off
- cls
- set /a change=0
- set /a count=0
- REM Asks for input. The script will loop back
- REM to this part in later sections of the code.
- :loop
- set /p "input=Input a number: "
- set /a change=input
- goto :skip
- REM Sets the variable 'input' to the same value
- REM as 'change'.
- :numtest
- if %change%==0 (
- goto :skip
- )
- set /a input=change
- :skip
- set /a count=count+1
- set /a "number=%input%" 2>nul
- REM Makes sure that the number is valid.
- if "%input%" NEQ "%number%" (
- cls
- Echo Please enter a valid number! &Echo.&Echo.
- goto :loop
- )
- Set /a Even=number%%2
- REM Mathematical equations depending on whether
- REM the input was even or odd.
- if %Even% EQU 0 (
- set /a answer=number/2
- ) else (
- set /a answer=number*3
- set /a answer=answer+1
- )
- if %answer%==1 (
- goto :print
- ) else (
- goto :check
- )
- REM Prints the number that you input at the start, and
- REM the number of calculations made.
- :print
- echo Your input (%change%) returned as 1.
- echo A total of (%count%) calculations were made.
- set /a change=change+1
- set /a count=0
- pause
- Echo.
- goto :numtest
- REM Sets 'input' to the value of 'answer' and repeats
- REM the calculations over and over until 'answer' is 1.
- :check
- set /a input=answer
- goto :skip
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement