MonteCarlo Simulation Roulette script/function

I already have a function that works for the Simulation of a Roulette and now i want to create a script to ask the Player(User) to choose a colour and his bet amount.
I tried to put the function in my script but the payout for the bet is not right, when i put the function in the script. But the function works and i get the payout.
When i choose for example red in input and 100 Euro for bet amount and i win then the payout is not right. If i win then the payout should be 200 Euro but here it is 106 and 96 Euro.
ans =
"rot"
106 96
My Script:
colour = input('Choose red,black or green ','s');
bet = input('choose bet: ','s');
while isnan(str2double(bet)) == true
bet = input('error.again please ','s');
end
disp(montecarlos(colour, bet))
function payout = montecarlos(colour, bet)
red = [3 12 7 18 9 14 1 16 5 23 30 36 27 34 25 21 19 32];
black = [26 35 28 29 22 31 20 33 24 10 8 11 13 6 17 2 4 15];
green = [38];
roulette = randi(38);
validatestring(colour,["red", "black", "green"])
if colour == "red" && any(roulette == red)
payout = 2*bet;
elseif colour == "black" && any(roulette == black)
payout = 2*bet;
elseif colour == "green" && any(roulette == green)
payout = 2*bet;
else % loose
payout = 0;
end
end

3 件のコメント

Rik
Rik 2021 年 2 月 15 日
You should use strcmp to compare the contents of strings and chars.
Also, where exactly are you converting your bet to a numeric value?
bet='50';
payout=bet*2
payout = 1×2
106 96
Image Analyst
Image Analyst 2021 年 2 月 16 日
Do not use 's' option in input():
bet = input('Specify the amount of your bet: ');
okan kolcak
okan kolcak 2021 年 2 月 16 日
thank you guys, now it works like i want it.

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeBuild and Analyze Curve Models についてさらに検索

質問済み:

2021 年 2 月 15 日

コメント済み:

2021 年 2 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by