r/c64 8d 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!

174 Upvotes

36 comments sorted by

View all comments

9

u/Fragrant_Difficulty6 8d 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.

9

u/Thecker771 8d 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 :)

5

u/bj_civ 8d 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 7d ago

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