Weekly Qbasic and Qb64 Lesson Topics
November 09, 2024, 06:24:23 pm
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Want to see a specific Tutorial? ASK!
 
  Home Help Search Arcade Links Staff List Login Register  

Calculate Age

Pages: [1]
  Print  
Author Topic: Calculate Age  (Read 6053 times)
ChatKing
Post Demos
*
Posts: 23


« on: November 21, 2011, 03:34:04 pm »

I have a complete code of Calculate Age but there is still a bug, can anybody find out and solve it and tell me. Thanks


Code:
DIM YourName AS STRING
DIM SHARED year1 AS INTEGER
DIM SHARED year2 AS INTEGER
DIM SHARED year3 AS INTEGER
DIM SHARED month1 AS INTEGER
DIM SHARED month2 AS INTEGER
DIM SHARED month3 AS INTEGER
DIM SHARED day1 AS INTEGER
DIM SHARED day2 AS INTEGER
DIM SHARED day3 AS INTEGER

CLS
INPUT "Your Good name, please : ", YourName
'assigning current dates to the varialbles
year1 = VAL(RIGHT$(DATE$, 4))
month1 = VAL(LEFT$(DATE$, 2))
day1 = VAL(MID$(DATE$, 4, 2))

Start

IF (day2 > day1) AND ((month1 = 4) OR (month1 = 6) OR (month1 = 9) OR (month1 = 11)) THEN
    day1 = day1 + 30
    month1 = month1 - 1
END IF

IF (day2 > day1) AND ((month1 = 1) OR (month1 = 3) OR (month1 = 5) OR (month1 = 7) OR (month1 = 8) OR (month1 = 10) OR (month = 12)) THEN
    day1 = day1 + 31
    month1 = month1 - 1
END IF

IF (day2 > day1) AND (month1 = 2) AND (year1 MOD 4 <> 0) THEN
    day1 = day1 + 28
    month1 = month1 - 1
END IF

IF (day2 > day1) AND (month1 = 2) AND (year1 MOD 4 = 0) THEN
    day1 = day1 + 29
    month1 = month1 - 1
END IF


IF (month2 > month1) THEN
    month1 = month1 + 12
    year1 = year1 - 1
END IF

'Calcualtion of year
day3 = day1 - day2
month3 = month1 - month2
year3 = year1 - year2


CLS
PRINT
PRINT YourName; " you are "; day3; " days "; month3; " months  and "; year3; " years old."





SUB Wrong
CLS
PRINT "Wrong Entry of your date of birth."
PRINT
PRINT "It should be valid year like 1998"
PRINT
PRINT "Valid month like 9"
PRINT
PRINT "Valid Date like 12"
PRINT
PRINT "or your computer date is not updated."
PRINT
INPUT "Press any key ............"; dummy$
Start
END SUB

SUB Start
year2 = 0
month2 = 0
day2 = 0

CLS
INPUT "Enter Year of Birth [eg 1999] : "; year2
IF (year2 < 1000) OR (year2 > year1) THEN Wrong
INPUT "Enter Month of Birth [eg 11]  : "; month2
IF (month2 < 1) OR (month2 > 12) THEN Wrong
INPUT "Enter Day of Birth [eg 23]    : "; day2
IF (day2 < 1) OR (day2 > 31) THEN Wrong
IF (day2 > 29) AND (month2 = 2) THEN Wrong
IF (day2 > 28) AND (month2 = 2) AND (year2 MOD 4 <> 0) THEN Wrong
END SUB
Report Spam   Logged

Pages: [1]
  Print  
 
Jump to:  

Powered by EzPortal
Bookmark this site! | Upgrade This Forum
SMF For Free - Create your own Forum


Powered by SMF | SMF © 2016, Simple Machines
Privacy Policy