Console quiz like program problem

Just starting out? Need help? Post your questions and find answers here.
BOOGIEMAN
User
User
Posts: 24
Joined: Sun Aug 07, 2005 10:29 pm
Location: Earth

Console quiz like program problem

Post by BOOGIEMAN »

I want to make a something like a quiz program, but I don't know how to avoid question repetition in console. This is example code:

Code: Select all

If  OpenConsole()
    somenumber = 50
    
    onestartshere:
    ClearConsole()
    Print("Question ONE is blah blah "+Str(somenumber)+": ")
    qqone = Int(Val(Input()))
    If qqone < 1 Or qqone > 10 : Goto onestartshere : EndIf
        
    twostartshere:
    PrintN("")
    Print("Question TWO is again blah "+Str(somenumber)+": ")
    qqtwo = Int(Val(Input()))
    If qqtwo < 5 Or qqtwo > 15 : Goto twostartshere : EndIf
    
    threestartshere:
    PrintN("")
    Print("Question THREE is some blah "+Str(somenumber)+": ")
    qqthree = Int(Val(Input()))
    If qqthree < 5 Or qqthree > 15 : Goto threestartshere : EndIf
    
    PrintN("")
    Print("Press ENTER to continue")
    Input()
    Goto onestartshere
    CloseConsole()
EndIf
End
and this is how I want it to look, whatever number I input (out of specified range)

Image

Is there a command like clearconsole(), but to clear and repeat last question only (leaving all preavious questions untouched)?
Of course, my quiz will have much more than three questions so I need to solve this first
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

Would something like:

Code: Select all

ConsoleLocate(LastX,LastY)
Print(Space(80))
ConsoleLocate(LastX,LastY)
Print("Q")
do it? But you have to keep track of the line positioning.
@}--`--,-- A rose by any other name ..
BOOGIEMAN
User
User
Posts: 24
Joined: Sun Aug 07, 2005 10:29 pm
Location: Earth

Post by BOOGIEMAN »

So, you say there is no easy way for solving my problem ? Well, nevermind then, thx
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

1 way would to store all previous lines in a buffer / string and then reprint them before next question..
BOOGIEMAN
User
User
Posts: 24
Joined: Sun Aug 07, 2005 10:29 pm
Location: Earth

Post by BOOGIEMAN »

Well I tried that first, but because of "Str(somenumber)" I can't store that in the string
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Code: Select all

If OpenConsole() = 0
  End
EndIf

ClearConsole()
somenumber = 50 
q = 0

Procedure Wrong()
  Shared q
  ConsoleLocate(0, q)
  Print(Space(80))
  ConsoleLocate(0, q)
EndProcedure

Repeat
  Wrong()
  Print("Question ONE is blah blah "+Str(somenumber)+": ") 
  answ = Val(Input())
Until (answ < 1 Or answ > 10)-1

PrintN("") : q + 1
Repeat
  Wrong()
  Print("Question TWO is again blah "+Str(somenumber)+": ") 
  answ = Val(Input())
Until (answ < 5 Or answ > 15)-1

PrintN("") : q + 1
Repeat
  Wrong()
  Print("Question THREE is some blah "+Str(somenumber)+": ")
  answ = Val(Input())
Until (answ < 5 Or answ > 15)-1

PrintN("")
Print("Press ENTER to continue")
Input()
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

ClearConsole() is all I can find.
BERESHEIT
okasvi
Enthusiast
Enthusiast
Posts: 150
Joined: Wed Apr 27, 2005 9:41 pm
Location: Finland

Post by okasvi »

http://www.purearea.net/pb/download/use ... ary_v1.zip

take a look in that incase there is what you need. i haven ever needed anything more than basics in PB so i dont know... hope this helps :)
BOOGIEMAN
User
User
Posts: 24
Joined: Sun Aug 07, 2005 10:29 pm
Location: Earth

Post by BOOGIEMAN »

OMG Trond, your code works perfectly ! :D Thank you, thanks all

By the way, I don't understand why when I remove -1 from

Code: Select all

Until (answ < 1 Or answ > 10)-1
or I change it to -2 (for example) code doesn't work properly ?
Post Reply