You are on page 1of 1

#include <iostream>

#include <math.h>
#define A 10000
#define ApostaMaxima 3000
int main()
{
int i, n, jugada, jugada_max=1, ronda_jugada_max=1;
int aposta_jugada, despesa_ronda, guanys_ronda, despesa_maxima=1,
guanys_totals=0;
char f;

// 0 - 17 Vermell
// 18 -36 Negre
// 37 = 0
// apostem al negre
srand(time(NULL));
for (i=1; i<A; i++)
{
jugada=1;
printf("\n** RONDA %4d *************º**********************\n", i);
do
{
despesa_ronda=(pow(3,jugada)-1)/2;
if (despesa_maxima<despesa_ronda) despesa_maxima=despesa_ronda;
if (despesa_ronda>=ApostaMaxima) break;
aposta_jugada=(pow(3,jugada-1));
n=rand()%38;
printf("Jugada=%3d Numero=%3d ", jugada, n);
if (n==37) printf("Zero ");
else if (n<18) printf("Vermell ");
else printf ("Negre ");
printf(" Aposta jugada =%3d Despesa acumulada en la ronda=%3d \
n",aposta_jugada, despesa_ronda);
++jugada;
//f=getchar();

} while (n<18);
guanys_ronda=2*pow(3,--jugada);
printf("**HA SORTIT NEGRE**\n**BENEFICI NET=BENEFICI RONDA-DESPESA RONDA=
%d-%d=%d\n",guanys_ronda,despesa_ronda,guanys_ronda-despesa_ronda);
guanys_totals+=guanys_ronda-despesa_ronda;
}
printf("\n-------------------RESUM DE %d RONDES-------------------\n",i);
printf("APOSTA MAXIMA=%d",despesa_maxima);
printf("\nGUANYS TOTALS EN %d RONDES %d euros\n",i,guanys_totals);
return 0;
}

You might also like