Wht is my failure?

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.

Respuestas (1)

Image Analyst
Image Analyst el 5 de Jun. de 2017
Editada: Image Analyst el 5 de Jun. de 2017

0 votos

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.

Categorías

Más información sobre Card games en Centro de ayuda y File Exchange.

Preguntada:

el 5 de Jun. de 2017

Editada:

el 5 de Jun. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by