1.

Solve : need to display number that is given by user?

Answer»

I need to display the number that is given by user on the command promt and it should go till 1

can any one help

ThanksTo get a number (or any PROMPT) from the user, do
Code: [Select]Set /P Number=Enter Number:
I dont understand what you mean by the 'and it should go to 1'

Do you mean count down to 1?Hi

yes it should go down till 1

User will give the input (for eg 5) then it should read like 54321
Quote from: tinkuy on July 07, 2010, 04:15:05 AM

Yes it should go down till 1
User will give the input (for eg 5) then it should read like 54321


C:\test>type numdown.BAT
@ECHO off
Set /P Number=Enter Number:
echo %number%
:count
set /a number=%number% - 1
echo %number%
if %number%==1 goto :end
goto :count
:end
echo Bye

Output:

C:\test>numdown.bat
Enter Number: 5
5
4
3
2
1
Bye
C:\test>
Quote from: marvinengland on July 07, 2010, 12:44:12 PM
4
3
2
1
0

OP explicitly stated

Quote
it should read like 54321


If the request is for horizontal we should oblige the OP:

Code: [Select]@echo off
setlocal enabledelayedexpansion

set /p num=Enter Number:

for /l %%v in (%num%, -1, 1) do (
set str=!str!%%v
)

echo %str%

You may want to ADD code to test if the user actually entered a number at the prompt and to cap the MAXIMUM value of the entered number.

The script is a batch file, so save with a bat or cmd extension and run from the command prompt.

Good luck. That will display all the numbers from N to 1 at once; he did mention a "countdown"...

Code: [Select]@echo off
REM milliseconds
REM no delay=0
set delay=1000

REM set "separator=... "
REM set "separator=, "
REM No separator:
REM set "separator="
set "separator= "

set /p number="Number = ? "
if exist tmp$$$.vbs del tmp$$$.vbs
for /l %%N in (%number%,-1,1) do (
>>tmp$$$.vbs echo Wscript.Sleep(%delay%^)
>>tmp$$$.vbs echo WScript.StdOut.Write "%%N%separator%"
)
cscript //nologo tmp$$$.vbs
echo.
del tmp$$$.vbs>nulno need for a separate vbs file


Code: [Select]@echo off
setlocal enabledelayedexpansion
set /p value=Enter value:
cls
echo %value%|findstr /r "[^0-9]" > nul
if errorlevel 1 goto A
exit
:A
REM milliseconds
REM no delay=0
set delay=1000

REM set "sep=... "
REM set "sep=, "
REM No separator:
REM set "sep="
set "sep= "
set list=%value%
set /a v=%value%-1
echo %list%
ping localhost -w %delay% -n 2 >nul
for /l %%a in (%v%,-1,1) do (
cls
set list=!list!%sep%%%a
echo !list!
ping localhost -w 1000 -n 2 >nul
)
pause
Sorry, mat123, I think your method is clunky. I don't really like flickery CLS stuff. Doing CLS is restrictive in terms of what you can do on the screen.

Quote from: Sidewinder on July 07, 2010, 01:33:26 PM
If the request is for horizontal we should oblige the OP:

Code: [Select]@echo off
setlocal enabledelayedexpansion

set /p num=Enter Number:

for /l %%v in (%num%, -1, 1) do (
set str=!str!%%v
)

echo %str%

You may want to add code to test if the user actually entered a number at the prompt and to cap the maximum value of the entered number.

The script is a batch file, so save with a bat or cmd extension and run from the command prompt.

Good luck.

SW your code is 150% better than anyone else in this thread. Of course, you are an hour late and a dollar short. How much are you paid for your efforts?Quote from: marvinengland on July 07, 2010, 05:21:12 PM
SW your code is 150% better than anyone else in this thread. Of course, you are an hour late and a dollar short. How much are you paid for your efforts?

Why is Billrich/Joanlong/Greg/Papyrus/MarvinEngland/wafflebrain frequently "picking" on SideWinder so often, and always in this sarcastic fashion?

Oh wait, I know the answer.

Envy.



Discussion

No Comment Found