中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-11-10 21:36
47,815 topics / 349,930 posts / today 0 new / 48,291 members
DOS批处理 & 脚本技术(批处理室) » Help me take a look at my code -- to determine a leap year, where is the problem?
Printable Version  3,932 / 16
Floor16 xycoordinate Posted 2007-02-28 21:54
中级用户 Posts 228 Credits 493 From 安徽

@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 ]
Floor17 slore Posted 2007-02-28 22:51
铂金会员 Posts 2,478 Credits 5,212
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.
Prev  1 2
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023