-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathage.bat
More file actions
30 lines (23 loc) · 749 Bytes
/
age.bat
File metadata and controls
30 lines (23 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
@echo off
setlocal enabledelayedexpansion
:input
set /p "birth_year=Enter your birth year: "
rem Check if the input is a number
set "is_number=true"
for /f "delims=0123456789" %%i in ("!birth_year!") do set "is_number=false"
if not !is_number! == true (
echo Invalid input. Please enter a valid number.
goto input
)
rem Get the current year
for /f "tokens=1 delims=" %%a in ('wmic os get localdatetime ^| find "."') do set "datetime=%%a"
set "current_year=!datetime:~0,4!"
rem Calculate the age
set /a age=current_year - birth_year
rem Validate that the age is not zero or less
if !age! leq 0 (
echo Invalid result. Age cannot be zero or less.
goto input
)
echo Your age is: %age% years
endlocal