A C programming problem. Please do it with batch processing. For example:
Input (seconds): 3662
Display: 0 days 1 hour 1 minute 2 seconds
Input (seconds): 3662
Display: 0 days 1 hour 1 minute 2 seconds
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!
| Rater | Score | Time |
|---|---|---|
| PPdos | +2 | 2007-01-17 10:27 |
| Rater | Score | Time |
|---|---|---|
| PPdos | +2 | 2007-01-17 10:22 |
, correction:@echo off
:begin
cls
echo.
set input=
set /p input= Please enter the number of seconds (press Enter directly to exit):
if not defined input exit
set /a SS=%input%%%60
set /a MM=%input%/60%%60
set /a HH=%input%/3600%%60
if %HH% GEQ 24 set /a HH=HH%%24
set /a DD=%input%/86400
echo.
echo %DD% days %HH% hours %MM% minutes %SS% seconds
echo.
pause
goto begin@echo off
:begin
cls
echo.
set input=
set /p input= Please enter the number of seconds (press Enter directly to exit):
if not defined input exit
for /f "tokens=1* delims=." %%i in ("%input%") do set input=%%i&&set .n=%%j
if "%.n%" == "" set .n=0
if "%.n:~1%" == "" set .n=%.n%0
if "%.n:~2%" == "" set .n=%.n%0
if "%.n:~0,1%" == "0" set .n=%.n:~1%
if "%.n:~0,1%" == "0" set .n=%.n:~1%
set /a SS=%input%%%60
set /a MM=%input%/60%%60
set /a HH=%input%/3600%%60
if %HH% GEQ 24 set /a HH=HH%%24
set /a DD=%input%/86400
echo.
echo %DD% days %HH% hours %MM% minutes %SS% seconds %.n% milliseconds
echo.
pause
goto beginOriginally posted by hxuan999 at 2007-1-16 13:37:
There is a problem when dealing with milliseconds. For example, entering 5485.3, then.3 should be 300 milliseconds, not 3 milliseconds.
hxuan: 2007-01-17 12:52
- @echo off&setlocal enabledelayedexpansion
- :begin
- cls
- echo;
- set input=
- set /p input= Please enter the number of seconds (press Enter directly to exit):
- if not defined input exit
- for /f "tokens=1* delims=." %%a in ("%input%") do set input=%%a & set D5=%%b00000
- for /l %%i in (4,-1,2) do set /a "D%%i=!input!%%60" && set /a "input=!input!/60"
- set "D5=!D5:~0,3!.!D5:~3,2!"
- set /a "D1=!input!%%24"
- echo;&echo; %D1% days %D2% hours %D3% minutes %D4% seconds %D5% milliseconds&echo;
- pause
- goto begin