/* Note:Your choice is C IDE */
#include "stdio.h"
#include"stdlib.h"
#include"conio.h"
#include"time.h"
#include"windows.h"
void gotoxy(int x,int y)/****vc++6.0中没有gotoxy()这个函数,用具有同样功能的API函数实现,将其封装成与TC函数同样的接口*****/
{
COORD coord={x,y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}
void guess(int n)
{
int acount ,bcount,i,j,k=0,flag,a[10],b[10];
do
{
flag=0;
srand((unsigned)time(NULL));
for(i=0;i<n;i++)
a[i]=rand()%10;
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
if(a[i]==a[j])
{
flag=1;
break;
}
}
}while(flag==1);
do
{k++;
acount=0;
bcount=0;
printf("guess:");
for(i=0;i<n;i++)
scanf("%d",&b[i]);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
if(a[i]==b[i])
{acount++;
break;}
if(a[i]==b[j]&&i!=j)
{ bcount++;
break;
}
}
printf("clue on:%d A %d B\n\n",acount,bcount);
if(acount==n)
{ if(k==1)
printf("you are the topmost rung of fortune's ladder!!\n\n");
else if(k<=5)
printf("you are a genius!!\n\n");
else if(k<=10)
printf("you are cleaver!!\n\n");
else
printf("you need try hard!!\n\n");
break;
}
}while(1);
}
main()
{int i,n;
while(1)
{system("cls");
gotoxy(15,6);
printf("1.start game");
gotoxy(15,8);
printf("2.rule");
gotoxy(15,10);
printf("3.exit\n");
gotoxy(25,15);
printf("please choose:");
scanf("%d",&i);
switch(i)
{
case 1:
system("cls");
printf("please input n;\n");
scanf("%d",&n);
guess(n);
Sleep(8000);
break;
case 2:
system("cls");
printf("the rules of the game\n");
printf("step1:input the number of digits\n");
printf("step2:input the number,separated by a space between two numbers\n");
printf("step3:A represent location and data are correct\n");
printf("\tB represent location is correct but data is wrong!\n");
Sleep(8000);
break;
case 3:
exit(0);
default:
break;
}
}
}
Guessing-numbers-game.zip_visual c
版权申诉
43 浏览量
2022-09-14
20:40:31
上传
评论
收藏 1KB ZIP 举报
钱亚锋
- 粉丝: 88
- 资源: 1万+
最新资源
- Yolov8改进---注意力机制:Polarized Self-Attention,效果秒杀CBAM、SE.html
- 人才网站设计-asp.net+sql-(系统源码)
- asp.net+sql人才网站设计-含系统源码
- C#应用的用户配置窗体方案
- python实现绘制爱心图形的代码
- JAVAWEB项目-校园订餐系统项目源码.zip
- flink-1.19.0-bin-scala-2.12.tgz flink-1.16.3-bin-scala-2.12.tgz
- javaWeb项目-物资管理系统项目源码.zip
- javaweb项目-物流配货项目源码.zip
- 使用C++基于颜色纹理特征的人脸活体检测实现-附项目源码.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈