#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<string.h>
using namespace std;
int main()
{
char next;
int shu,shu1;
do
{
shu=rand()%100+1;
system("cls");
printf("请输入一个1-100的数: ");
scanf("%d",&shu1);
getchar();
while(shu1!=shu)
{
if(shu1<shu)
{
printf("小了\n再输入一个数吧 ");
scanf("%d",&shu1);
}
if(shu1>shu)
{
printf("大了\n再输入一个数吧 ");
scanf("%d",&shu1);
}
}
printf("恭喜你,猜对了!!!\n");
getchar();
printf("还要玩吗?y/n\n");
next=getchar();
getchar();
}
while(next=='y'||next=='Y');
}
#include<iostream>
#include<stdlib.h>
#include<string.h>
using namespace std;
int main()
{
char next;
int shu,shu1;
do
{
shu=rand()%100+1;
system("cls");
printf("请输入一个1-100的数: ");
scanf("%d",&shu1);
getchar();
while(shu1!=shu)
{
if(shu1<shu)
{
printf("小了\n再输入一个数吧 ");
scanf("%d",&shu1);
}
if(shu1>shu)
{
printf("大了\n再输入一个数吧 ");
scanf("%d",&shu1);
}
}
printf("恭喜你,猜对了!!!\n");
getchar();
printf("还要玩吗?y/n\n");
next=getchar();
getchar();
}
while(next=='y'||next=='Y');
}
本文介绍了一个简单的猜数字游戏程序,使用C++语言编写。程序通过随机生成一个1到100之间的整数,并提示用户输入猜测的数字。如果用户的猜测不正确,则给出“大了”或“小了”的提示,直至猜中为止。此外,还提供了是否继续游戏的选择。
&spm=1001.2101.3001.5002&articleId=79462243&d=1&t=3&u=ff120d3a1d334e2082fb38a9db3754df)
3765

被折叠的 条评论
为什么被折叠?



