ZTY9820
2021-04-26 01:11
采纳率: 70%
浏览 59

<C语言> 输入y除外的字母为什么程序还是继续进行了?大佬们帮帮忙

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main(void)

{
    char start;
    int num, gold, times, balance;
    start = 'y';
    printf("Do u want wealth overnight?\n");
    printf("Let´s play a game\n");
    printf("How much money do you want to pay for the game?\n");
    scanf("%d",&gold);
    times = gold/2;

while (start == 'y' || start == 'Y')

 {

            while (gold >= 2)
        {
            printf("You have %d chances.\n",times);
            srand( (unsigned)time( NULL ) );
            num = rand()% 15+3;
            printf("Your number is : %d\n",num);
            fflush(stdin);

            if (num == 18 || num == 3)
            {
                gold = gold + 8;
                times = gold/2;
                printf("Congratulations! You win 10 euro!\n");
                printf("Your balance is %d. \n",gold);
            }

            else if (num >= 16 || num == 5)
            {
                gold = gold + 1;
                times = gold/2;
                printf("Congratulations! You win 3 euro!\n");
                printf("Your balance is %d. \n",gold);
            }

            else
            {
                gold = gold - 2;
                times = gold/2;
                printf("You lose, try again!\n");
                printf("Your balance is %d. \n",gold);
            }

            printf("Do you want to try again?(y/n)\n");
            scanf("%c", &start);
            fflush(stdin);

        }
        printf("Your balance is not enough, Welcome to come again.");
 }

return 0;
}
 

2条回答 默认 最新

相关推荐 更多相似问题