Jump to content

So I have an assignment to make a programme with small basic, its very simplistic. But I'm running to the problem that with the code under the marker "start" the points always get increased with 100 and at the marker "start2" the points consistently get decreased with 75.

 

 

ready:
TextWindow.WriteLine("Do you want to bet? yes(1)? High risk, high reward(2)? Or not(3).")
answer = TextWindow.ReadNumber()
If answer = 1 Then
  Goto start
ElseIf answer = 2 then
  Goto start2  
Else 
  TextWindow.WriteLine("Maybe you'll reconsider?")
  Goto ready
EndIf

points = 100
start:
TextWindow.WriteLine("Ok lets go.")
var1 = Math.GetRandomNumber(10)
If 5 < var1 < 9 Then 
  points = points + 100
ElseIf 9 < var1 < 10 then
  points = points + 200
Elseif 1 < var1 < 5 then
  points = points - 100
EndIf
TextWindow.WriteLine("You rolled " + var1 + ". You now have " + points + " points.")
Goto ready

start2:
TextWindow.WriteLine("How many of your points do you want to bet?")
bet = TextWindow.ReadNumber()
var2 = Math.GetRandomNumber(10)
If 1 < var2 < 5 Then
  points = points - bet + bet * 0.25
ElseIf 5 < var2 < 8 then 
  points = points - bet + bet * 1.5
ElseIf 8 < var2 < 9 then
  points = points - bet + bet * 2.5
Elseif 9 < var2 < 10 then 
  points = points - bet + bet * 4
EndIf
TextWindow.WriteLine("You rolled " + var2 + ". You now have " + points + " points.")
Goto ready

 

What to do? Is it something with the if/elseif construction or does it have to do with the points variable or is it something else?

 

thanks a lot in advance!

Link to comment
https://linustechtips.com/topic/758734-microsoft-small-basic/
Share on other sites

Link to post
Share on other sites

If 5 < var1 < 9 Then 

 

so say we roll a 3 so var1 (you really need to name your variables meaningful names) now holds 3.

 

If 5 less then 3 and 3 < 9 then do this.

 

so unless you rolled a 10 var1 will always be less than 9 and well run the first statement. 

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
https://linustechtips.com/topic/758734-microsoft-small-basic/#findComment-9589507
Share on other sites

Link to post
Share on other sites

You also  have  problems like  if  9 < nr < 10 ... this would never happen as there's no number between 9 and 10.

 

this would maybe make more sense and be easy to follow ..

 

points = 100 
 
ready:
TextWindow.WriteLine("Do you want to bet? [1] Yes [2] High risk, high reward [3] No")
answer = TextWindow.ReadNumber()
nr = Math.GetRandomNumber(10)
If answer>2 Then 
  Goto close
ElseIf answer = 1 Then
  Goto start
ElseIf answer = 2 then
  Goto start2  
EndIf


start:
TextWindow.WriteLine("Ok lets go.")

'  10 => +200 , 5..9 => +100 , 1..4 => -100

If nr > 9 Then 
  points = points + 200
ElseIf nr > 4 then 
  points = points + 100
else
  points = points - 100
EndIf

TextWindow.WriteLine("You rolled a " + nr + ". You now have " + points + " points.")
Goto ready

start2:
TextWindow.WriteLine("How many of your points do you want to bet?")
bet = TextWindow.ReadNumber()
points = points - bet
'  10 => 4x  , 8..9 => 2.5x , 5..7 => 1.5x , 1..4 => 0.25x
If nr > 9 Then 
  points = points + bet * 4
ElseIf nr > 7 then 
  points = points + bet * 2.5
elseif nr > 4 then 
  points = points + bet * 1.5
Else
  points = points + bet * 0.25
EndIf

TextWindow.WriteLine("You rolled " + nr + ". You now have " + points + " points.")
Goto ready 

close:

 

Link to comment
https://linustechtips.com/topic/758734-microsoft-small-basic/#findComment-9589515
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×