KinnguRabbit
KinnguRabbit
2016-05-25 03:13
采纳率: 75%
浏览 1.8k
已采纳

C语言 做了一个猜数游戏,如何在3次失败以后显示正确的数字printf应该加在哪里?

#include
#include
#include
#include
int main()
{
{
printf("********************************\n I want to play a game with you\n********************************");
}
int c;
printf("\nChoose your Rank LV1~LV3:");
scanf_s("%d", &c);
printf("\nYou have 3 chances");
int a, b;
srand(time(NULL));
if (c == 1)
{
a = 1 + (rand() % 10); //get a number from 1~10//
}
if (c == 2)
{
a = 1 + (rand() % 100); // get a number from 1~100//
}
if (c == 3)
{
a = 1 + (rand() % 1000); //get a number from 1~1000//
}
int n = 0;
while (a && n++ < 3)
{
printf("\nint a number:");
scanf_s("%d", &b);
if (a == b)
{
printf("good job\n");
break;
}
if (n != 3)
{
if (b > a)
printf("try a smaller number");
if (b < a)
printf("try a bigger number");
}
}
getchar();
return 0;
}

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • caozhy
    已采纳

    printf("正确数字是%d", a);
    getchar();

    点赞 评论
  • caozhy

    添加在倒数第4行。

    点赞 评论

相关推荐