#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int R = 1;
int P = 2;
int S = 3;
int i;
int Pscore = 0;
int Cscore = 0;
int choice;
srand(time(NULL));
printf("Rock=1 , Paper= 2, and Scissors= 3\n");
while(1)
{
printf("Enter your choice:");
scanf_s("%d", &choice);
int computer = rand() % 3 + 1;
if (choice == 1) {
if (computer == 1) {
printf("Draw\n");
}
if (computer == 2) {
printf("Computer Wins!\n");
Cscore = Cscore + 1;
}
if (computer == 3) {
printf("Player Wins\n");
Pscore = Pscore + 1;
}
}
else if (choice == 2) {
if (computer == 2) {
printf("Draw\n");
}
if (computer == 3) {
printf("Player Wins!\n");
Pscore = Pscore + 1;
}
if (computer == 1) {
printf("Computer Wins!\n");
Cscore = Cscore + 1;
}
}
else if (choice == 3) {
if (computer == 3) {
printf("Draw\n");
}
if (computer == 2) {
printf("Computer Wins!\n");
Cscore = Cscore + 1;
}
if (computer == 1) {
printf("Player Wins!\n");
Pscore = Pscore + 1;
}
}
else {
break;
}
}
if (Cscore > Pscore) {
printf("컴퓨터 승리 %d 대 %d\n", Cscore, Pscore);
}
else if (Cscore < Pscore) {
printf("플레이어 승리 %d 대 %d\n", Pscore, Cscore);
}
else if (Cscore = Pscore) {
printf("최종결과 비김\n");
}
return 0;
}
이 코드에서
#include <stdlib.h>
#include <time.h>
srand(time(NULL));
int computer = rand() % 3 + 1;
얘네 간략하게 설명좀...형님들 ㅠㅠ
#include <stdio.h>의 의미는 아는데 쟤네 두개는 모른다는?? 것입니까??
api 사용 선언, 랜덤숫자생성, 1,2,3 중에 하나 저장
http://blog.naver.com/qbarche39/220666948220,
srand
감사합니다 행님들