Qbasicnews.com
March 28, 2020, 06:14:40 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1] 2 3
  Print  
Author Topic: QUIZ GAME WITH SCORE  (Read 7383 times)
tabnewflax
New Member

Posts: 22


« on: March 14, 2004, 05:26:42 PM »

Im doing a simple quiz game containging the capitals of the world. And Im trying to add score to it so you will get one score for every right.

1.The problem is when you answer right the first time and goes to the second and answer right again the counter resets I have tried a lot of things but cannot come up with any good soulution. Here is the code so you can see and help me better.

2. Another question to how do I do if the user inputs Kabul or KABUL. I have tried to input LCASE$ and those things but I dont get it to work and I dont think it does eiter.
----------------------------------------------------
afghanistan:
INPUT "Afghanistan: ", city$
IF city$ = "kabul" then
            goto albania
else
             goto afgwrong
end if

afgwrong:
print "Wrong!"
             goto albania

INPUT "Albania: ", city$
IF city$ = "tirana" then
            goto sweden
else
             goto albwrong
end if

albwrong:
print "Wrong!"
             goto sweden

'AND SO ON.....................................................

And I'm sure there is an easier way to do this, if you know which you probably do plz write it down  :wink:
Logged
Zack
*/-\*
*****
Posts: 3974



WWW
« Reply #1 on: March 14, 2004, 05:49:14 PM »

Ewwww...Look at all that GOTO.
Code:
INPUT "Afghanistan: "; City$
IF LCASE$(City$)="kabul" THEN
   PRINT "Right!"
   Afghanistan_Correct=1
ELSE
   PRINT "Wrong!"
END IF
INPUT "Albania: "; City$
IF LCASE$(City%)="tirana" THEN
   PRINT "Right!"
   Albania_Correct=1
ELSE
   PRINT "Wrong!"
END IF
'And so on...

At the end, you can just check if the Afghanistan_Correct is equal to 1 or not to see if you got Afghanistan correct. If it is equal to one, then you got it correct. Otherwise, you got it wrong. You can do that with all the other Countryname_Correct variables that you put.
Logged

f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Mango
Wandering Guru
***
Posts: 360



« Reply #2 on: March 14, 2004, 07:04:48 PM »

Hi tabnewflax,

Like all programming projects, there are many ways to accomplish the same thing.  If I were wanting to solve your problem, I would structure the program as follows:

1st, create a file containing the countries and capitals as follows:

"IntCaps.txt"
Country, Capital
Italy, Rome
England, London


Then, I'd make the main program read the file into a pair of arrays, 1-containing the countries, and the other containing the capitals.  Then, I'd select a random array element, display the country and ask the user for the capital.  

The advantage of this method is that you could then use the same program to quiz any two related words...for example, you could make another file containing the "element name" and "symbol" if, for example you were studying chemistry...  

another advantage is that all your data is located in 1-place...separate from the program...in a format that is easy to modify.  Also, you could give the user choice...take the geography quiz, or the chemistry quiz...and altering it to give the song/artist quiz would be trivial.
Logged
tabnewflax
New Member

Posts: 22


« Reply #3 on: March 15, 2004, 06:04:24 AM »

Zack... I don't get how the score things work, and I can't write the underline than it stands end-of-statement. I guess it might be ok to skip the underline, but I dont get it how I shall check it in the end I need a more detailed explanation of how getting the scores together in the end. But thanx for the other stuffs it cleared up a bit.

And thanx Mango for yours too but that is a bit advance for me now I think, I will deal with your idea later Wink
Logged
Zack
*/-\*
*****
Posts: 3974



WWW
« Reply #4 on: March 15, 2004, 11:47:03 AM »

Quote from: "tabnewflax"
Zack... I don't get how the score things work, and I can't write the underline than it stands end-of-statement. I guess it might be ok to skip the underline, but I dont get it how I shall check it in the end I need a more detailed explanation of how getting the scores together in the end. But thanx for the other stuffs it cleared up a bit.

And thanx Mango for yours too but that is a bit advance for me now I think, I will deal with your idea later Wink

Don't worry at all about the underscores (the _ symbols) in the name of the variables. See, an underscore is just another legal character for a variable. Using one doesn't change how the variable acts, or what you can do with it. Just ignore it if you like - you can even change it's name to AlbaniaCorrect or AfghanistanCorrect.

Okay, basically, it asks you for the name of a capital of a country. You enter the name, and it's stored in the City$ variable. Then is compares the lowercase of City$ (LCASE$(City$)) to the correct city (in all lowercase, of course). If you got it right, it says "Right!" and it sets a variable called Countryname_correct to 1. Then, at the end of the program if you want to tally up how many city names you got correct, just check if the appropriate Countryname_correct variable is equal to 1.
See?
Logged

f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #5 on: March 15, 2004, 12:08:15 PM »

GRR! Underscores are not allowed in QB! Tongue
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #6 on: March 15, 2004, 12:49:31 PM »

Unless you hack it.
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Zack
*/-\*
*****
Posts: 3974



WWW
« Reply #7 on: March 15, 2004, 01:23:25 PM »

Quote from: "na_th_an"
GRR! Underscores are not allowed in QB! Tongue

Huh? Yes they are... :normal:
Code:
A_B_C_D=5
PRINT A_B_C_D

Works fine.
Logged

f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
tabnewflax
New Member

Posts: 22


« Reply #8 on: March 15, 2004, 03:07:16 PM »

Quote from: "Zack"
Then, at the end of the program if you want to tally up how many city names you got correct, just check if the appropriate Countryname_correct variable is equal to 1.
See?


I'm sorry that I am nagging so much, but I still don't get how to display the score at the end Tongue
Logged
R@dioman
Ancient QBer
****
Posts: 410



« Reply #9 on: March 15, 2004, 03:12:48 PM »

Whenever you get the answer correct, add an amount to a Score variable, and when it's time to display it, use the PRINT command like this:

PRINT Score%

Remember to use the appropriate variable type. If the score won't ever be higher than 32767, then use an integer (Score%). If it goes higher, use a long (Score&). More info on data types in QB's help.
Logged

Zack
*/-\*
*****
Posts: 3974



WWW
« Reply #10 on: March 15, 2004, 03:14:06 PM »

Ohhhh, I see what you want. That's pretty simple:
Code:
INPUT "Afghanistan: "; City$
IF LCASE$(City$)="kabul" THEN
   PRINT "Right!"
   Score=Score+1
ELSE
   PRINT "Wrong!"
   REM Score=Score-1 'Un-REM this to make it so that you lose a point with every wrong answer
END IF
INPUT "Albania: "; City$
IF LCASE$(City%)="tirana" THEN
   PRINT "Right!"
   Score=Score+1
ELSE
   PRINT "Wrong!"
   REM Score=Score-1 'Read above comment for info on this line
END IF
'And so on...
PRINT Score

And then the variable Score holds the total score (the total number of answers, in this case).
Logged

f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #11 on: March 15, 2004, 03:57:29 PM »

Quote from: "Zack"
Quote from: "na_th_an"
GRR! Underscores are not allowed in QB! Tongue

Huh? Yes they are... :normal:
Code:
A_B_C_D=5
PRINT A_B_C_D

Works fine.


No, it doesn't. At least in QB 4.5:



Quote from: "QB help"
A BASIC variable name may contain up to 40 characters. The characters  
allowed in a variable name are letters, numbers, the period (.), and  
the type-declaration characters (%, &, !, #, and $). The first character  
in a variable name must be a letter. If a variable begins with FN, it is  
assumed to be a call to a DEF FN function.  
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Z!re
*/-\*
*****
Posts: 4599


« Reply #12 on: March 15, 2004, 04:08:24 PM »

This code:
Code:
pri_
nt "Hello w_
orld!"


If you open it in QB you will se: Print "Hello World!"

_ is used as line continuation. I use . instead if I want a eparator in the variable name:

This_Var becomes This.Var...
Logged
Zack
*/-\*
*****
Posts: 3974



WWW
« Reply #13 on: March 15, 2004, 05:04:35 PM »

I keep making this variable-name stupid mistakes! Dammit. Thanks, Nath.
Logged

f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #14 on: March 15, 2004, 09:30:10 PM »

The _ line separation thing only works when loading in a program, or something.
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Pages: [1] 2 3
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!