#2
by box » 2年前
なんでプレイヤーの手もランダムに決めさせるんですかね?
手で入力したいんじゃないんですか?
コード:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
int player, computer;
srand((unsigned int) time(NULL));
computer = rand() % 3 + 1;
do {
printf("your hand(1:stone, 2:scissors, 3:paper) > ");
scanf("%d", &player);
if (player != 1 && player != 2 && player != 3) {
printf("bad hand\n");
}
} while (player != 1 && player != 2 && player != 3);
// printf("%d %d\n", player, computer);
if (player == computer) {
printf("same hand\n");
}
else if (player == 1 && computer == 2 ||
player == 2 && computer == 3 ||
player == 3 && computer == 1) {
printf("player win!\n");
}
else {
printf("computer win!\n");
}
return 0;
}
なんでプレイヤーの手もランダムに決めさせるんですかね?
手で入力したいんじゃないんですか?
[code]
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
int player, computer;
srand((unsigned int) time(NULL));
computer = rand() % 3 + 1;
do {
printf("your hand(1:stone, 2:scissors, 3:paper) > ");
scanf("%d", &player);
if (player != 1 && player != 2 && player != 3) {
printf("bad hand\n");
}
} while (player != 1 && player != 2 && player != 3);
// printf("%d %d\n", player, computer);
if (player == computer) {
printf("same hand\n");
}
else if (player == 1 && computer == 2 ||
player == 2 && computer == 3 ||
player == 3 && computer == 1) {
printf("player win!\n");
}
else {
printf("computer win!\n");
}
return 0;
}
[/code]