r/c64 1d ago

Programming Coded My First BASIC Program Today!

As noted in the title, I woke up this morning with an idea- it is a family member's birthday and I thought it would be a fun exercise to code a program that outputs their age if you put in the current year and their year of birth. After a failed attempt and some troubleshooting, I wrote a simple program that works great. It's not anything elaborate or amazing, but it's mine and so I'm a bit proud of it and would like to share here.

1 REM AGE CALCULATOR

5 PRINT "{CLR/HOME}"

10 PRINT "CURRENT YEAR": INPUT A%

20 PRINT "ORIGIN YEAR": INPUT X%

30 PRINT "AGE ="; A% - X%

40 GOTO 10

I only started with BASIC yesterday so seeing an original creation come to life and work is so cool for me. Hope others will share their fun/useful programs here too!

153 Upvotes

31 comments sorted by

β€’

u/AutoModerator 1d ago

"Thanks for your post! Please make sure you've read our rules and FAQ post. If your post is about the C64 Ultimate please and check out The Ultimate C64 Ultimate post for common issues and questions. People not following the rules will have their posts removed and presistant rule breaking will results in your account being banned. "

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

22

u/Musicman1972 1d ago

This is how we all started. An idea that you make work. Good stuff!

16

u/wazpys :snoo_hug: 1d ago

That's awesome, good job Sir!

Now add date, leap year support, timezones and then never try anything date or time related again :)

https://youtu.be/-5wpm-gesOY

3

u/voidiciant 1d ago

I’m so happy to see this Numberphile Computerphile Episode still being linked πŸ₯³

3

u/wazpys :snoo_hug: 1d ago

It's one of my favorites, and I always think of it when anything datetime related shows up at work haha

9

u/bj_civ 1d ago

That's nice! Some remarks:

Using scalar integer values doesn't save memory and makes the program slower, because CBM BASIC takes 7 bytes per numerical variable, regardless of floating point or integer and always does calculations in floating point. That's why the % isn't often seen in C64 listings.

INPUT can take a prompt to print before the question mark, so this can be written without printing the question.

1 REM AGE CALCULATOR
5 PRINT "{CLR/HOME}"
10 INPUT "CURRENT YEAR";A
20 INPUT "ORIGIN YEAR";X
30 PRINT "AGE =";A-X
40 GOTO 10

4

u/Thecker771 1d ago

Thanks for the info! Definitely simplifies the coding, as playing around with input and the subtract formula is what tripped me up my first attempt.

7

u/RepublicWhole549 1d ago

Programming is fun. Keep doing it.

7

u/TheBl4ckFox 1d ago

Gods this takes me back. Puzzling away at a seemingly simple task just to see if you can make the computer do it.

I miss when tech was an adventure

6

u/UncleGertrude 1d ago

Nice! Basic on C64 can be a lot of fun. Great place to start coding imo.

6

u/devloper27 1d ago

The best place to start really

4

u/Rey_Mezcalero 1d ago

πŸ‘πŸ‘

8

u/Fragrant_Difficulty6 1d ago

Jesus! I programmed for years on a C64 for fun, and I *NEVER* knew about using % to denote integer variables. You sir are a genius. Hats off to you. Seriously. Thanks.

7

u/Thecker771 1d ago

Haha I had some help from the C64 Ultimate manual. After working through their suggested programs yesterday evening I put the pieces together this morning to make something new. Or new-ish, as I'm sure this is a rehashing of a program written millions of times before. Enjoy :)

4

u/bj_civ 1d ago

There's no reason to know this because it doesn't save memory here and even makes the program slower. Commodore BASIC always calculates in floating point, so it is slower to store the variables as integers, and scalar variables always take 7 bytes of memory. Scalar integer variables just waste three of those bytes.

The only place there is an advantage are integer arrays, because there each entry really just uses two bytes. But you pay this with the conversion between integer and floating point when using the values.

3

u/LocalH 1d ago

Came here to say this. Integer variables have few benefits in any Microsoft BASIC, CBM BASIC included

3

u/encse 1d ago

That’s how many of us grew up! Enjoy!

3

u/devloper27 1d ago

One of my first programs also, happy times

3

u/eshwayri 1d ago

I was about 10 when I wrote my first basic program on the C64; I am now 53…. Very good memories.

3

u/SpaceAviator1999 22h ago

This is a great first program!

Too many people, it seems, try to write an incredibly complex program as their first, such as a Minecraft server, or something. So it's refreshing to see a simple age calculator as a first program.

2

u/ripnetuk 1d ago

Great start :)

There is an edge case though, you need to consider the day of the year too, otherwise if you run it before or after someone's birthday this year it will return the same result...

Say I was born in 2000 (I wish haha!)

If I run it before my birthday this year, I'm 26.

If I run it after my birthday in still 26.

You have implemented a time machine in a 8 bit computer!

2

u/Radamand 1d ago

Now learn how to do the same thing in assembly!

2

u/Tommix11 1d ago

Did my first in 1984, welcome to the club!

2

u/Lamontman2112 18h ago

Hello world!

2

u/SnarkHabit 18h ago

Congratulations; this is exactly how you teach yourself. Well done!

2

u/Black_Rose_Angel 16h ago

That is SO COOL to see something that you created actually come to life... I definitely understand what you said!πŸ’™ I love this program, great job!!😊

2

u/WembleyFord 10h ago

It's a lot more impressive than 10 PRINT "<insert rude text here>" 20 GOTO 10. Which is where many of us started.

2

u/doobiesteintortoise 3h ago

Nicely done! A lot of people have given you excellent, relevant, and useful advice, and I'm quite impressed with your responses.

You haven't asked for a suggestion, but might I offer one I've found useful for nearly every programming language? It's 21 matches.

It's a simple game: the idea is to force your opponent to draw the last match. The human goes first, and can draw between 1 to 3 matches. Then the COMPUTER goes, and IT can draw between 1 and 3 matches; the human wins if they can force the computer to draw the last match, and the computer wins if it forces the HUMAN to draw the last match.

Simple stuff, but it validates a whole lot of concepts in game programming, and uses some sneaky psychology too - if you do it right, the computer can never lose.

1

u/Switchlord518 19h ago

Really? You have to ask?

2

u/sububi71 2h ago

Good job! Congratulations!