d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Looping For Help With A Quick Question.
12Next
Add Reply New Topic New Poll
Member
Posts: 31,187
Joined: Aug 31 2008
Gold: 28,306.50
Trader: Trusted
Oct 13 2012 01:25pm
Provde the steps to Create a batch file that:

a) prompts a user for their favorite operating system
b) prints their selection to the screen (You picked the _________ !)
c) saves their selection to a file called fav-opsys.txt in their home directory.



anyone able to help out with this, i was out of town the day they did this at school >.>
Member
Posts: 10,812
Joined: Oct 15 2009
Gold: Locked
Warn: 20%
Oct 13 2012 01:55pm
Code
@echo off
cls
:MENU
ECHO.
ECHO PRESS 1 or 2 to select your favoriate OS.
ECHO.
ECHO 1 - I'm retared, I like Windows
ECHO 2 - I like Linux
ECHO 3 - WTF is an OS? (exit)
ECHO.
SET /P M=Type 1 or 2, or 3, then press ENTER:
IF %M%==1 GOTO SAVE1
IF %M%==2 GOTO SAVE2
IF %M%==3 GOTO EOF
:SAVE1
echo "You picked Windows, you noob!"
echo windows > %HOMEPATH%/fav-opsys.txt
GOTO EOF
:SAVE2
echo "You picked Linux, nice!"
echo linux > %HOMEPATH%/fav-opsys.txt
GOTO EOF
:EOF
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Oct 13 2012 02:01pm
theres many ways.

you can use the choice.com file but it doesnt work on some os's

you can use the COPY CON command to copy text to a temp file

Code
ECHO Enter some input, and press Enter when ready . . .
ECHO ←[13;0;64;13p
COPY CON USRINPUT.TMP
ECHO ←[13;13p
CLS
ECHO You typed:
TYPE USRINPUT.TMP


or you can use the SET command

Code
@echo off
SET userenter=
echo userenter >> c:\%pathcodetohomedirectory%\file.tmp


just go google lol shits easy
Member
Posts: 31,187
Joined: Aug 31 2008
Gold: 28,306.50
Trader: Trusted
Oct 13 2012 02:19pm
so would this one work>


Code
echo Which Operating System is your favorite? Linux(L) or Windows(W) or OSX(O)?
@ECHO off
@CHOICE /C:LWO
IF ERRORLEVEL 3 GOTO three
IF ERRORLEVEL 2 GOTO two
IF ERRORLEVEL 1 GOTO one
GOTO end
:one
ECHO You picked the Linux Operating System !
echo linux > %HOMEPATH%/fav-opsys.txt
GOTO end
:two
ECHO You picked the Windows Operating System !
echo windows > %HOMEPATH%/fav-opsys.txt
GOTO end
:three
ECHO You picked the OSX Operating System !
echo OSX > %HOMEPATH%/fav-opsys.txt
GOTO end
:end
@PAUSE
Member
Posts: 10,812
Joined: Oct 15 2009
Gold: Locked
Warn: 20%
Oct 13 2012 02:22pm
I'd switch the first two lines, but that is just aesthetics; it should work.
Member
Posts: 31,187
Joined: Aug 31 2008
Gold: 28,306.50
Trader: Trusted
Oct 13 2012 02:32pm
Quote (Azrad @ Oct 13 2012 03:22pm)
I'd switch the first two lines, but that is just aesthetics; it should work.


thanks. :0


okay one more, just did a few questons.


Create a batch file that:
a) accepts two integers as parameters
b) prints the sum of these integers to the screen
c) multiplies the integers and prints the result to the screen
d) saves the results to a file called math.txt in the user's home directory.

(Mostly need part a rest should be easy now)

This post was edited by Phyxios on Oct 13 2012 02:37pm
Member
Posts: 10,812
Joined: Oct 15 2009
Gold: Locked
Warn: 20%
Oct 13 2012 03:02pm
Quote (Phyxios @ Oct 13 2012 01:32pm)
thanks. :0


okay one more, just did a few questons.


Create a batch file that:
a) accepts two integers as parameters
b) prints the sum of these integers to the screen
c) multiplies the integers and prints the result to the screen
d) saves the results to a file called math.txt in the user's home directory.

(Mostly need part a rest should be easy now)



this would be easy, the only hard part is verifying that the user input is in fact an integer..... If you don't care about this let me know.
Member
Posts: 31,187
Joined: Aug 31 2008
Gold: 28,306.50
Trader: Trusted
Oct 13 2012 03:13pm
Quote (Azrad @ Oct 13 2012 04:02pm)
this would be easy, the only hard part is verifying that the user input is in fact an integer..... If you don't care about this let me know.


dont care about the verification :P
Member
Posts: 31,187
Joined: Aug 31 2008
Gold: 28,306.50
Trader: Trusted
Oct 13 2012 03:34pm
so this is my job wich obviously wont do the saving properly because the %d% will just overwrite the %c%... can you fix? >.<


@echo off
set /p a=enter an int
set /p b=enter another int
set /a c=a+b
set /a d=a*b
echo %c%
echo %d%
echo %a% > %HOMEPATH%\math.txt
echo %b% > %HOMEPATH%\math.txt
echo %c% > %HOMEPATH%\math.txt
echo %d% > %HOMEPATH%\math.txt
@pause
Member
Posts: 10,812
Joined: Oct 15 2009
Gold: Locked
Warn: 20%
Oct 13 2012 03:40pm
This is what I did. Now I will look at what you did.

Code
:SETUP
@ECHO off
cls

:GETFIRSTINTEGER
ECHO "Enter your first integer"
SET /P FirstNumber=Please Enter a Number:
SET "Output=Your first number was  %FirstNumber%"
ECHO %Output% > %HOMEPATH%/math.txt

:GETSECONDINTEGER
ECHO "Enter your second integer"
SET /P SecondNumber=Please Enter a Number:
SET "Output=Your second number was  %FirstNumber%"
ECHO %Output% >> %HOMEPATH%/math.txt

:SUMTHEM
SET /A SUM=FirstNumber + SecondNumber
SET "Output=The sum of your numbers is %SUM%"
ECHO %Output%
ECHO %Output% >> %HOMEPATH%/math.txt

:MULTIPLYTHEM
SET /A MULTIPLY = FirstNumber * SecondNumber
SET "Output=The product of your numbers is %MULTIPLY%"
ECHO %Output%
ECHO %Output% >> %HOMEPATH%/math.txt

:ENDOFPROGRAM
@PAUSE
Go Back To Programming & Development Topic List
12Next
Add Reply New Topic New Poll