Wht is my failure?
9 views (last 30 days)
Show older comments
I want to write a function, which Shows the Martingale Strategy for a Gambler. For the beginning I started to Code a single Round for the game:
function Capital = roulette1 (Startcap) %% Capital should Show the Money at the end of the round, if the Gambler won or lost the round %% StartCap should be the Money the Gambler is starting with, for Example: the Gambler Starts with 100$
Capital = EndCap
if rem(randi(37),2)==0 %% if the Gambler is winning the game he wins the Money he was Setting, in here he is betting 1$
EndCap = Startcap +1
else %% or the Gambler loses 1$
Endcap = Startcap - 1
end
endMatlab Shows me always the error that the variable Endcap is undefined. What is my failure? Thanks for help and answers.
0 Comments
Answers (1)
Image Analyst
on 5 Jun 2017
Edited: Image Analyst
on 5 Jun 2017
When you say this:
Capital = EndCap
exactly what value do you think the undefined EndCap should have? 3? pi? 42? How is the code supposed to know? It doesn't - you need to tell it. It can't just make up some arbitrary value for EndCap.
Perhaps you want this:
Capital = Startcap;
if rem(randi(37),2) == 0
%%if the Gambler is winning the game he wins the Money he was Setting, in here he is betting 1$
Capital = Capital + 1;
else %%or the Gambler loses 1$
Capital = Capital - 1;
end
I don't see a need for EndCap at all since Capital is the running balance - the amount of money the gambler currently has.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!