China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

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!

中国DOS联盟论坛
The time now is 2026-06-23 13:55
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Help me take a look at my code -- to determine a leap year, where is the problem? View 3,143 Replies 16
Floor 16 Posted 2007-02-28 21:54 ·  中国 安徽 马鞍山 电信
中级用户
★★
Credits 493
Posts 228
Joined 2007-02-16 00:38
19-year member
UID 79596
Gender Male
From 安徽
Status Offline

@echo off
set /p year=Please enter the year:
set /a x=%year%%%4
set /a y=%year%%%100
set /a z=%year%%%400
if %x%==0 (
if %y%==0 (
if %z%==0 (
set term=1
) else (
set term=0
)
) else (
set term=1
)
) else (
set term=0
)


Eyes are dazzled!
Re-learning: namejm's "A Notable Issue in the if...else... Statement"
http://www.cn-dos.net/forum/viewthread.php?tid=22704&fpage=1&highlight=if

Modify a bit:

@echo off
set /p year=Please enter the year:
set /a x=%year%%%4
set /a y=%year%%%100
set /a z=%year%%%400
set term=0
if %z% == 0 set term=1
if %x% == 0 (if not %y% == 0 set term=1)



[ Last edited by xycoordinate on 2007-2-28 at 09:04 AM ]
Floor 17 Posted 2007-02-28 22:51 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
The conditions for determining a leap year are:
1. Divisible by 4 but not by 100.
2. Divisible by both 100 and 400.

Isn't this contradictory?

Can a year divisible by 400 and 100 satisfy the first condition?

First judge whether condition 2 is not satisfied, then look at condition 1...

Century years must be divisible by 400 to be leap years, while non-century years just need to be divisible by 4.
Forum Jump: