用C++编一个猜数字的游戏。最好用Visual C++6.0,并给出运行结果
答案:1 悬赏:0 手机版
解决时间 2021-01-11 05:13
- 提问者网友:我一贱你就笑
- 2021-01-10 05:20
用C++编一个猜数字的游戏。最好用Visual C++6.0,并给出运行结果
最佳答案
- 五星知识达人网友:第幾種人
- 2021-01-10 06:42
#include
#include
#include
int main(int argc, char * argv[])
{
srand((unsigned)time(NULL));
int a = rand()%100;
a+=1;
int b,c;
c = 0;
while (c < 10)
{
printf("Please enter a number: ");
if (scanf("%d", &b) == 0)
{
fprintf(stderr, "Invalid entry.
");
return EXIT_FAILURE;
}
else
{
if (b == a)
{
printf("You are correct, the number is %d!
", a);
printf("You used %d times to get the answer.
", c);
break;
}
else if (b > a)
printf("The number is bigger than it suppose to.
");
else
printf("The number is smaller than it suppose to.
");
c++;
}
if (c == 10)
{
printf("You used 10 times, please try again!
");
break;
}
}
return EXIT_SUCCESS;
}
#include
#include
int main(int argc, char * argv[])
{
srand((unsigned)time(NULL));
int a = rand()%100;
a+=1;
int b,c;
c = 0;
while (c < 10)
{
printf("Please enter a number: ");
if (scanf("%d", &b) == 0)
{
fprintf(stderr, "Invalid entry.
");
return EXIT_FAILURE;
}
else
{
if (b == a)
{
printf("You are correct, the number is %d!
", a);
printf("You used %d times to get the answer.
", c);
break;
}
else if (b > a)
printf("The number is bigger than it suppose to.
");
else
printf("The number is smaller than it suppose to.
");
c++;
}
if (c == 10)
{
printf("You used 10 times, please try again!
");
break;
}
}
return EXIT_SUCCESS;
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯