C
CoreyWhite
I wrote a program that shows some incredibly curious probabilities. It
is a simple game where you guess a number between 0 and 2 that the
computer thinks up. What is origonal about this game is the computer
tells you before hand if you got the number right and you can decide if
you want to play or not. The computer keeps track of all your wins,
all your losses, and as is possible all of your didn't wins but didn't
loses. What is strange about this program is that the total
probability of you winning the game can be undefined if you never lose,
but play a number of undefined games where you haven't won or lost.
Please tell me what is going on here, because it is very curious.
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int gen_random(long int M) {
double r;
double x;
int y;
int count;
r = ( (double)rand() / ((double)(RAND_MAX)+(double)(1)) );
x = (r * M);
y = (int) x;
return(y);
}
int
main(int argc, char *argv[]) {
int N = ((argc == 2) ? atoi(argv[1]) : 1);
int result = 0;
srand(N); /*initialize random number generator*/
int win=0;
int notwin=0;
for(int cnt=0; cnt<10; cnt++){
int play=0;
int R=0;
R=gen_random(3);
int guess=0;
printf("Guess my number, its between 0 and 2: ");
scanf("%d",&guess);
printf("My number was %d, do you still want to play (1/0)? ", R);
scanf("%d", &play);
if(R==guess && play==1){
win++;
printf("You won, your total wins are: %d\n",win);
}
if(R==guess && play==0){
printf("You don't want to play? Your total losses are %d\n",notwin);
notwin=notwin;
}
if(R!=guess && play==0){
notwin=notwin;
printf("Good decision, your total losses are %d\n",notwin);
}
if(R!=guess && play==1){
notwin++;
printf("You want to play? Your total losses are %d\n",notwin);
}
}
printf("Wins: %d\n",win);
printf("Didn't win: %d\n",notwin);
printf("Wins / Didn't Win: %d\n", win/notwin);
return(0);
}
is a simple game where you guess a number between 0 and 2 that the
computer thinks up. What is origonal about this game is the computer
tells you before hand if you got the number right and you can decide if
you want to play or not. The computer keeps track of all your wins,
all your losses, and as is possible all of your didn't wins but didn't
loses. What is strange about this program is that the total
probability of you winning the game can be undefined if you never lose,
but play a number of undefined games where you haven't won or lost.
Please tell me what is going on here, because it is very curious.
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int gen_random(long int M) {
double r;
double x;
int y;
int count;
r = ( (double)rand() / ((double)(RAND_MAX)+(double)(1)) );
x = (r * M);
y = (int) x;
return(y);
}
int
main(int argc, char *argv[]) {
int N = ((argc == 2) ? atoi(argv[1]) : 1);
int result = 0;
srand(N); /*initialize random number generator*/
int win=0;
int notwin=0;
for(int cnt=0; cnt<10; cnt++){
int play=0;
int R=0;
R=gen_random(3);
int guess=0;
printf("Guess my number, its between 0 and 2: ");
scanf("%d",&guess);
printf("My number was %d, do you still want to play (1/0)? ", R);
scanf("%d", &play);
if(R==guess && play==1){
win++;
printf("You won, your total wins are: %d\n",win);
}
if(R==guess && play==0){
printf("You don't want to play? Your total losses are %d\n",notwin);
notwin=notwin;
}
if(R!=guess && play==0){
notwin=notwin;
printf("Good decision, your total losses are %d\n",notwin);
}
if(R!=guess && play==1){
notwin++;
printf("You want to play? Your total losses are %d\n",notwin);
}
}
printf("Wins: %d\n",win);
printf("Didn't win: %d\n",notwin);
printf("Wins / Didn't Win: %d\n", win/notwin);
return(0);
}