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
  end

Matlab Shows me always the error that the variable Endcap is undefined. What is my failure? Thanks for help and answers.

답변 (1개)

Image Analyst
Image Analyst 2017년 6월 5일
편집: Image Analyst 2017년 6월 5일

0 개 추천

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.

카테고리

도움말 센터File Exchange에서 Card games에 대해 자세히 알아보기

질문:

2017년 6월 5일

편집:

2017년 6월 5일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by