Programming Qbasic Part Five

Hi and welcome to lesson 5. Well well well, you have learned a lot's of commands?
Well, not so many if we consider how many there are still to learn =) Anyway, with those commands you have learned is possible to make some simple guessing etc. games. I made these tutorials with different idea than most of other's beginners tutorials. I dont wana mess your head with FUNCTIONs, SUBs and so on. I didn't also want to start with How you make code that look's good. or other that stuff. If you get interest with QBasic, you will learn those things soon, but this point I wanted to show you some basic codes and beginners ways to use them.

Now there will come one new command only, well two commands but they work together almost same way than FOR and NEXT commands. I dont explain on this lesson. Ill just give you a code, comment it as good as I can. Type it on your QBasic, run it and most of all STUDY IT GOOD. Here we go.

``````' Here we make sure that few variables are 0
Rounds = 0
Points = 0

CLS INPUT " What's your name"; Name\$

DO 'Here we begin loop
Rounds = Rounds + 1 'Counts rounds
CLS ' Clears the screen
GuessTotal = Guess1 + Guess2 ' Count's how mutch your guessed numbers are

' In next part of code ill use also PRINT " Here you get what that line does =)"
Dice1 = INT(RND * 6 + 1) ' Randomizes first dice
PRINT " Dice 1 is "; Dice1
IF Dice1 = Guess1 OR Dice1 = Guess2 THEN Points = Points + 1 : PRINT " Dice 1 guessed right!!!!! You got 1 point!"

Dice2 = INT(RND * 6 + 1) ' Randomizes second dice
PRINT " Dice 2 is "; Dice2
IF Dice2 = Guess1 OR Dice2 = Guess2 THEN Points = Points + 1: PRINT " Dice 2 guessed right!!!!! You got 1 point!"

IF GuessTotal = Dice1 + Dice2 THEN  Points = Points + 1: PRINT "Sum of dices matched with your sum of guessed numbers!!! You got 1 point!"

PRINT " You have played "; Rounds; " rounds"
PRINT " You have "; Points; " points"
INPUT " Press ENTER to continue"; Wait\$

LOOP UNTIL Points > 10 ' This ends loop that DO started when you have 10 points.

CLS PRINT " You made it, you got 10 points in total "; Rounds; " rounds."
END```
```

It aint perfect, it need lots of changes to get shorter. Of course it works that way fine. Just Run it and play.
Study that code and try to think how you could make it shorter, simpler or how to add something new to it. After that, try make your own game.
Not this but like a lottery for example. If you got no idea what to do, take a day or two break of QBasic. Hurry aint friend of programmer.

Very soon you got to start studying variables and arrays. There are already great tutorials about them so at this point im not planning to make my own.
Few hints at end of this tutorial series.

• If you got feeling that you cant move forward with learning or you think that you are running out of ideas then take a break. Few days with out programming makes good time to time.
• Dont move on too quickly. When you learn a new command, study it and how it works. Dont just test it on one program. Use it so many different ways than you can and then take next command under learning.
• Do not just start some program by coding it. When you got idea of game or program make it on your mind first. How it works, what you can do with it and so on. Good planning is 90% of programming
• Also dont start too big projects. There is big change to loose your interest of programming if you try to do some huge game in beginning and cant finish it.
• And last and my opinion important. Study codes that exists but NEVER use ready code in your program. Make always your own code. Using some one elses codes wont teach you so mutch than making your own codes.

There is no short cut to become a good programmer in a week or even in month. It takes time, lots of it. And there are not also thing as a all learned programmer. Allways is something more to learn. Ask if you got problem, dont fear asking. Even the most experienced programmers gets stuck time to time. They can do it with very simple things.

Thats all, I think. I hope this tutorial series helped you some how.

E.K.Virtanen