I hope to post fun little bits of code and then try to comment them as fully as I can in attempts to get people new to QB64 up and running faster. Feel free to ask questions to get clarification, I may have screwed up.
This is something I posted at Friends after messing around with a dice roll thing at Aurels place:
BTW that's here: https://friends-of-basic.freeforums.net
and here: http://basic4us.epizy.com/forum/index.php
Here is original post:
Then I decided if I really wanted to do something Friendly I should comment more fully for Beginners.
So here is same resulting output with lots of comments:
I decided to post the 2nd one here first because A) this is my favorite forum and B) it is likely to be seen more here.
C) I thought it an excellent first post for this thread.
This is something I posted at Friends after messing around with a dice roll thing at Aurels place:
BTW that's here: https://friends-of-basic.freeforums.net
and here: http://basic4us.epizy.com/forum/index.php
Here is original post:
Code: (Select All)
_Title "Playing for Charity: 100 dice" ' b+ 2023-05-20
' A game that no one loses!
Randomize Timer
Dim As Long roll, Charity, me, r
For roll = 1 To 100
r = Int(Rnd * 6) + 1
Print " Roll number:"; roll; "is"; r
If r < 5 Then Charity = Charity + r Else me = me + r
Print: Print " I get 5's and 6's:"; me
Print " Charity gets 1, 2, 3, 4's:"; Charity
Print: Print " zzz... press any to continue"
Print
Sleep
Next
Print: Print " Treat ";
If me > Charity Then Print "yourself"; Else Print "Others";
Print " specially well today."
Then I decided if I really wanted to do something Friendly I should comment more fully for Beginners.
So here is same resulting output with lots of comments:
Code: (Select All)
' The following not in original code but a very good habit to get into, it will save you
' from your typos. 3P = Proper Programming Practice :)
Option _Explicit ' This forces you to Dim (or ReDim) your variables before you use them.
' !!! EXCEPTION !!! should you do something like DEFINT A-Z or DEFLNG A-Z then everything
' is automatically. :O
' If the following is in the first lines of your program and you go to save it, QB64 IDE
' will suggest your _Title string for your .bas file name when starting from File > New.
_Title "Playing for Charity: 100 dice" ' b+ 2023-05-20 < 3P author and date with _Title.
' A game that no one loses! < 3P a quick summary or comments. I usually list versions here.
Randomize Timer ' this is here so I don't play the same game over on each run.
' Dim As Long roll, Charity, me, r < 3P originally I had this, but really strong 3P is
' declaring all your variables first 2nd part of Option _Explicit team.
Dim As Long roll ' this tracks the For loop index eg roll number
Dim As Long r ' this is for random to be used to store the dice roll value.
Dim As Long Charity ' variable to store running total points for Charity
Dim As Long me ' variable to store running total points for me.
' I am using Long because I want Integers and Long is easier to type and doesn't take more
' time than Integer Type. So I get a range of over 32,000 with 0 cost.
For roll = 1 To 100 ' the main loop does 100 rolls
r = Int(Rnd * 6) + 1 ' Rnd = 0 to .9999 Multiply by 6 and have 0 to 5.9999
' Take Int(0 to 5.99999) get 0,1,2,3,4,5
' Add 1 for 1 to 6
'
' Print something; < with semi colon ending keeps the print head right where it stops.
' Print something, < with comma tabs the print head right to set column widths
' Print something < nothing after literals or variables moves print head to next line.
' Print will automatically start on next line if can't finish print job on current one.
' Print: < finishes last print line or starts new one by inserting blank line.
Print " Roll number:"; roll; "is"; r ' this first line reporting roll number and roll.
If r < 5 Then Charity = Charity + r Else me = me + r ' this decides if me or Charity
' gets the rolled points
' This reports the running scores and tells Sleep is activated so we have to press a key
' to continue game.
Print: Print " I get 5's and 6's:"; me
Print " Charity gets 1, 2, 3, 4's:"; Charity
Print: Print " zzz... press any to continue"
Print
Sleep
Next ' end of 100 rolls loop onto summary result.
Print: Print " Treat ";
If me > Charity Then Print "yourself"; Else Print "Others";
Print " specially well today."
' the End < 3P if you had GoSubs after this End put an End statement here.
I decided to post the 2nd one here first because A) this is my favorite forum and B) it is likely to be seen more here.
C) I thought it an excellent first post for this thread.
b = b + ...