Help for my program?

Blitz3D Forums/Blitz3D Beginners Area/Help for my program?

JadenReichelt(Posted 2016) [#1]
I am making a program for a lottery game and I cant figure out a way so that the bet wont be greater than the money they have in the bank. So far I know I can use the command

If bank<0 Then
bank=bank+bet1
Print "The bet cant be over the banked money"

So that if the bank is below with the bet then the bet will be added back to the bank then I need a way to go back to where it asks you to enter the bet so that it wont go under their balance. Here is a small section of the program so you can see if you know what to do :D

;--------------------------------------------------------------;
Function lotterygame()

Color 117,152,229
Print "Your bank has $" + bank + " in it."
Color 126,194,52

bet1=Input ("Please enter your bet here: $")
bank=bank-bet1

If bank<0 Then

bank=bank+bet1
Print "The bet cant be over the banked money"

End If
;----------------------------------------------------------;

And for some reason I tried even more and for the part where I tried to add the bet back in, it added it more than it should of which confused me.

If you want to copy the commands above and put it in to the reply with how you would
change it and explain the changes you would make that would be fantastic !

If you have any ideas how to go back up to where they enter the bet that would be great :D Thank you

Once I am done and my game is completed I will share it all with you guys so you guys can test it out for yourselves !


JadenReichelt(Posted 2016) [#2]
Never mind I think I figured it all out,

;------------------------------------------------------;

bet1=Input ("Please enter your bet here: $")
bank=bank-bet1


If bank<0 Then
While bank<0
bank=bank+bet1
bet1=Input ("Please enter your bet here: $")
Wend
End If

bank=bank-bet1

;-----------------------------------------------------------------;

If you guys have any suggestions still that would be great and I will defiantly look at them. Thanks and as soon as Im done with the game I will post it.


Dan(Posted 2016) [#3]
hi,

instead of doing bank=bank-bet1 , you could check, if the bet1 is higher than the amount of the bank.
bank=500
bet=0

Repeat
.betagain      

Print "Bank:"+bank
Print
bet1=Input("Please enter your bet here, in $ :")

If bet1>bank             ;check if bet1 is greater than bank eg. if 600 is greater than 500
                         ;It will accept lower and same numbers as the bank
        Print "your bet cannot be higher than the ammount in the bank"
	;Goto betagain    ;if yes, jump back to label betagain
;  edit: the goto statement in this example is useless, but if you have more processing after endif, then you remove the comment
Else
	bank=bank-bet1   ;it is not greater, you can substract the ammount from the bank safely
EndIf

Until bank=0  ;end the game when bank has 0 in it

Print "The bank has 0$, The game is over!"
WaitKey()


p.s. if you enter negative numbers, the bank will gain, so if you dont want that, make another check if bet1 is lower than 0.


JadenReichelt(Posted 2016) [#4]
Thank you Dan, I will look more into that ! I am newer to blitz as I am using it in my high school programming class. I have not quite learned about the labels but I will look more into that. I am pretty sure I am almost done with the game. I need to check out the negative number thing again and figure a way around that. It is really colorful and fun (in my opinion). I hope you will check it out :D Thanks again and have a good day


Guy Fawkes(Posted 2016) [#5]
When you want to turn a negative number to a positive one, just use "Abs()" :)

~GF


JadenReichelt(Posted 2016) [#6]
So GF, what I did was....

=================================================

Function nocheating()

If bank<0 Then
While bank<0
Color Rnd(255),Rnd(255),Rnd(255)
Print "You cant bet more than you have silly goose"
bank=bank+bet1
Color Rnd(255),Rnd(255),Rnd(255)
bet1=Input ("Please enter your bet here: $")
bank=bank-bet1
Wend
End If

If bet1<0 Then
While bet1<0
Color Rnd(255),Rnd(255),Rnd(255)
Print "You cant bet a negative number silly goose"
bank=bank+bet1
Color Rnd(255),Rnd(255),Rnd(255)
bet1=Input ("Please enter your bet here: $")
bank=bank-bet1
Wend
End If

End Function

==================================================

Then I made that repeat over and over til they put in a number that was acceptable

Thanks for the suggestion I will keep it in mind

~JR~


Guy Fawkes(Posted 2016) [#7]
Bro, you're new here so please next time you paste long code, use [ codebox ]REPLACE WITH LONG CODE RIGHT HERE[ /codebox ] or for SHORT code: [ code ]REPLACE WITH SHORT CODE RIGHT HERE[ /code ] & be sure to remove the spaces in the "codebox" & "code" tags. :)

~GF


JadenReichelt(Posted 2016) [#8]
Thanks Guy Fawkes I am new and ill keep that in mind :D


Guy Fawkes(Posted 2016) [#9]
Np! =)

~GF


Dan(Posted 2016) [#10]
Here is a small code which will help you to understand abs(), as Guy Fawkes suggested:

(To end this, type 10 or -10)


Repeat

  bet1=Input("Enter a number, 10 to quit:")

  Print "Number without abs("+bet1+")"

  bet1=Abs(bet1)

  Print "Number after abs("+bet1+")"
  print

Until bet1=10



the other way is to check, if bet1 is lower than 0
to do that, use this

bet1=input("Number?:>")
if bet1<0 
  print "The number is lower thant 0"
elseIf bet1=0
  print "The number equals zero"
elseIf bet1>0
  print "The number is greater than 0"
EndIf

waitkey()



JadenReichelt(Posted 2016) [#11]
Thank you Dan :D I think I will use the abs, it looks easier than what I was trying to figure out ! I hope I can share the program soon :D Almost done

~JR