How do i update a value and + add int values constantly
I have an int value and i wanna add numbers to it and i want it to update.
for example if i add 10 to the int i dont want the int to be set as onlly 10 i want it so if i add another 10 it gets to 20 if you know what i mean
40 Replies
Do just that
Instead of setting your value to
10
, set it to the current value plus 10So like
n +=10
?example
int balance
int deposit
deposit // sets by the user typing it
and then
balance += deposit
so something like that
Yes
but then when i type in a new deposit the balance sets to the current deposit i typed
my deposit beforehand doesnt exist
Show $code
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
If your code is too long, post it to: https://paste.mod.gg/if you know what i mean
Are you restarting the program every time?
BlazeBin - mgtkujoglbtm
A tool for sharing your source code with the world!
no
it is in another language but hope you get it
Your
instatdgausding
method is said to be returning something
But you don't do anything with that returntbh i dont know what return really does haha
It returns the value from the inside of the method, to the outside of it
ah should i remove the return value
and add a void instead?
Angius#1586
REPL Result: Success
Result: string
Compile: 537.812ms | Execution: 39.386ms | React with ❌ to remove this embed.
Assuming saldo is the one you want Keep the saldo Int at the top because you make a new one every time the function is called $scope
you probably want
$scopes
$scopes
thing a
is available in scope A
and scope B
thing b
is available only in scope B
You should be using this value
This method returns your sedlar
But since you don't assign the return to anything when the method is called, it's discarded
Then your saldo method has an inner variable
saldo
that exists only within that methodwill this work for me ?
Do you need to sum two numbers?
Then no
It's just an example demonstrating what
return
doesah
Is saldo or sedlar the “balance”
saldo
is the blaance
balance*
insättning is withdraw
sedlar is money
(would've been a whole lot easier if your code was in English 😛 )
hahahahahahahaha
can rewrite it fast in english
I think you should keep saldo at the top because the saldo method creates a new saldo every time it’s called
Yeah
That should be just about the structure
BlazeBin - suwnqmfoflxp
A tool for sharing your source code with the world!
here
@Squirtle try this at the top. Does it work?
Note that the only change I made was adding a balance at the top
(Also make sure to change the to
yeah
did it
doesnt work
S;
still same issue
when it gets the money amount
but then when i try to put in a new value
it doesnt change
it changes to the new only
it doesnt add the old one
The balance needs to be in the scope of the class
Then, the withdraw/deposit method needs to modify that balance
Then, the display method has to display that balance
@Squirtle found the problem. Your code says
=+
when it should be +=
lmao
that fixed it
hahahahahahhahahaah
(On a side note it’s interesting how c# has a
+
unary operator when I can’t think of a use for it)Angius#1586
REPL Result: Success
Result: int
Compile: 407.660ms | Execution: 22.447ms | React with ❌ to remove this embed.
Huh, you're right