21ゲームを作りました。
無駄に処理しているところやバグをこれ以上自分ではわかりません。
ご教授ください。
C
1#include <stdio.h> 2#include <stdlib.h> 3#include <time.h> 4#include <stdbool.h> 5int main(void) { 6 int input = 0, cpu = 0, answer = 0; 7 bool p_lose = false, c_lose = false; 8 9 printf("--------21ゲーム--------\n"); 10 while (answer < 21) { 11 srand((unsigned)time(NULL)); 12 printf("1から3までの数字を入力してください。\n"); 13 printf("あなた : "); 14 scanf("%d", &input); 15 if(input > 3) 16 continue; 17 else 18 answer += input; 19 20 if (answer == 20) c_lose = true; 21 22 cpu = rand() % 3 + 1; 23 printf("あいて : %d\n", cpu); 24 answer += cpu; 25 printf("現在の数字%d\n\n",answer); 26 if (answer == 20) p_lose = true; 27 28 if (p_lose == true || c_lose == true) 29 break; 30 31 } 32 if (p_lose == true){ 33 printf("あいての勝ち\n"); 34 } else if (c_lose == true){ 35 printf("あなたの勝ち\n"); 36 } 37 return 0; 38} 39