코딩?한것 도움좀 부탁드립니다
쇼콜라데
몬티홀에 관한 것인대요,
car와 choice는 랜덤으로 pick하고
newchoice를 프로그램에서 계산하고(무조건 선택을 바꿈)..newchoice가 car랑 같으면 win이 1씩오르는..걸 만들고싶은대
계속win/total이 1/1 2/2 3/3 4/4 5/5 .. 계속 win되내요..
도움부탁드립니다!
#include stdio.h
#include time.h
#include stdlib.h
#define CLEARCARD {one=two=three=0;}
#define MARKCARD(x) {if(x==1) one=1; else if(x==2) two=1; else three =1;}
#define GETUNMARKED(x) {if(one==0) x=1; else if(two==0)x=2; else x=3;}
int main(void)
{
int one, two, three;
int car, choice, third, newchoice;
int ans, cont, tmp, temp;
int win = 0, total = 0;
printf(입력횟수:);
scanf_s(%d, &cont);
while (cont total){
srand((unsigned int)time(NULL)); //시간별 난수발생
car = rand() % 3 + 1; // car를 1~3중 하나로 랜덤하게 pick
choice = 1 + (car + rand() % 2) % 3; //choice를 1~3중 하나로 랜덤하게 pick
CLEARCARD //third는 car도 choice도 아닌 값
MARKCARD(car)
MARKCARD(choice)
GETUNMARKED(third)
CLEARCARD //newchoice는 choice도 third도 아닌 값
MARKCARD(choice)
MARKCARD(third)
GETUNMARKED(newchoice)
if (newchoice == car){
win = win + 1;
}
total = total + 1;
printf(win/total=%d/%d\n, win, total);
}
}