Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Making a calendar in Qbasic
#1
Hi.

Yesterday, my class was given the assignment to make a calendar in Qbasic. The goal of the calendar is for the user to input a date (month, day, year) and then the program prints out the month containing that date. It can be any day of any month, of any year.

The only problem is... I have no idea what to do. I'm not very good in programming (I'm a B- student) so I'm kind of stuck whereas others are being successful.

Anyways, we were given this equation to help us find any date in history:

N = D + 2*M + INT(3*(M+1)/5 + Y + INT(Y/4) - INT(Y/100) + INT(Y/400)+2

Obviously d is the day, m is the month, and y is the year.

We were also told that when we found N, we should mod it by 7, and the result would the day of the week. For example, if N mod 7=0, then the day would be Saturday. If N mod 7=1, then the day would be Sunday. 2=Monday, 3=Tuesday, 4=Wednesday, 5=Thursday, 6=Friday

And for months, January and Feburary use 13, 14 (respectively) for the month number, plus they use the previous year. For example, if the input is 2,13, 2001 (Feb, 13th, 2001) then the program would need to use 14, 13, 2000.

The program prints out the calendar in question, and then allows the user to go again.

As you can guess, I'm extremely confused and have no idea where to start. I don't expect anyone to do the project for me, but I'd greatly appreciate it if somebody could give me a push in the right direction.

Thank you.

EDIT- I neglected to mention that I can design the calendar just fine. It's the whole science behind the dates and whatnot that's got me completely confused. Thanks again.
Reply
#2
Blader5489,

This is just a f.y.i. type thing.
For what it's worth, the formula you were given doesn't actually work all that well.
(I don't know if your instructor is aware of that or not. :roll: )
I discovered this while designing a calendar of my own.
I can't recall just where the problem was, but I remember it was off so far that it made a BIG difference in a short while. :o
adsherm
Reply
#3
I tried the following program, using the data posted by Blader, and it works well:
Code:
CLS
'This program correctly reports the day of the week for Feb 1 of the years
'1980, 2004, 2005, 2098 and 2099
INPUT "Enter the date you want to know the day for, as mm/dd/yyyy ", NDate$
M = VAL(MID$(NDate$, 1, 2)) + 12
D = VAL(MID$(NDate$, 4, 2))
Y = VAL(MID$(NDate$, 7, 4)) - 1

N = D + 2 * M + INT(3 * (M + 1) / 5) + Y + INT(Y / 4) - INT(Y / 100) + INT(Y / 400) + 2


DOW = N MOD 7
IF DOW = 0 THEN D$ = "Saturday"
IF DOW = 1 THEN D$ = "Sunday"
IF DOW = 2 THEN D$ = "Monday"
IF DOW = 3 THEN D$ = "Tuesday"
IF DOW = 4 THEN D$ = "Wednesday"
IF DOW = 5 THEN D$ = "Thursday"
IF DOW = 6 THEN D$ = "Friday"
PRINT "For the date entered, "; NDate$; ", the day is "; D$
END
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Reply
#4
If you do his homework, he won't learn. You are not helping him at all.

It's not me, it's on the rules of this site.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#5
Ralph,

I think it was an earlier year that I used, but I'm not positive.
I just remember it was off. I'll have to see if I can find it again so I can see just what it was that it had a problem with.
adsherm
Reply
#6
Ralph,

What inspired you to add 12 to the month, and subtract 1 from the year?
*****
Reply
#7
Quote:If you do his homework, he won't learn. You are not helping him at all.

It's not me, it's on the rules of this site.

Ummm... how do you know this?
Actually, he might have learned alot, now that he sees how the formula was actually put to use in a programming language.

Just some thoughts Big Grin

Cya!

Nemesis
Reply
#8
na_th_an:
Sorry, I just thought he needed to understand how to use the formula he received from his teacher. My thoughts and intention were not to do his homework for him. But, I'll think more about your remark the next time I think of helping out with a homework problem.

Moneo:
The original post reads:
Quote:And for months, January and Feburary use 13, 14 (respectively) for the month number, plus they use the previous year. For example, if the input is 2,13, 2001 (Feb, 13th, 2001) then the program would need to use 14, 13, 2000.
so, it isn't too hard to see that a whole year has been subtracted and made up by adding 12 months.

Nemesis:
I sure hope you're right! After all, if the OP doesn't learn from understanding the formula, he will have missed out on that part of the problem. And, the rest of the problem remains, the actual creation of the proper calender month, plus the screen presentation and printout coding which, I would think, is still a substantial part of the problem he has to resolve.
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Reply
#9
>so, it isn't too hard to see that a whole year has been subtracted
>and made up by adding 12 months.

I think you misunderstood. It's only January and February that
need to be modified (to become months 13 and 14 respectively),
the other months retain their usual ordinal numbers. The reason
for this is to make February (which is the odd one out) the 'last'
of the months, for example so leap years work correctly.

If you're interested in more calendar functions in BASIC (and you
don't mind them being in a different dialect) try downloading the
free version of BBC BASIC for Windows and looking in the DATELIB
library. Most of the functions there could be relatively easily
converted to QBASIC:

http://www.rtrussell.co.uk/products/bbcw...nload.html

Richard.[/quote]
url=http://www.bbcbasic.org/]Visit www.bbcbasic.org for BBC BASIC[/url]
Reply
#10
I guess that our friend, Blader, the original poster, has some more work to do! I just tested the program (and Blader's formula) for January of various years. If I had tested for October, I guess I would have gotten an error! Sad

But I, personally, am not interested in calender-making; I only thought of helping Blader get on the right road. Big Grin
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)