C
C#3y ago
TOLOXI

trying to create an atm

i wanna create an atm system that only draws out 100 dollar bills. So if you wanna draw out 670 dollars an error would pop out that tell you hat youre only able to withdraw 600 dollars but the code isnt running
12 Replies
TheBoxyBear
TheBoxyBear3y ago
You need to reference the Text property of the label
TOLOXI
TOLOXIOP3y ago
how do i do that?
TheBoxyBear
TheBoxyBear3y ago
lblPengar.Text otherwise you're referencing the label itself and assigning it, which fails cause the value is string
TOLOXI
TOLOXIOP3y ago
ohhhhh i thoguht that only applied to textboxes
TheBoxyBear
TheBoxyBear3y ago
All controls All you can set in the designer you can set in code through properties of the control Funny enough if you look at the Designer.cs file, you'll find it's generating the entire form with the same lines you would use to modify it in code The designer just helps generating the designer file
TOLOXI
TOLOXIOP3y ago
its not working as its supposed to hahaha
TheBoxyBear
TheBoxyBear3y ago
You're converting to Int and setting to double so you lose precision If it's intentional to round down, you can also do this by casting var rounded = (int)decimalValue
TOLOXI
TOLOXIOP3y ago
ill try that thanls for the help thanks
TheBoxyBear
TheBoxyBear3y ago
also for converting from string to number, always use TryParse int.TryParse("1", out var num)
TOLOXI
TOLOXIOP3y ago
thats what my teacher told me but im used to convert.toint32
TheBoxyBear
TheBoxyBear3y ago
The problem with that is it will crash if you enter something that's not a number With TryParse you can put that in an if and if it returns false you can abort and send an error message
TOLOXI
TOLOXIOP3y ago
thanks a lot for the advice ill keep that in mind i appreciate the help a lot

Did you find this page helpful?