📄 猜测储物位置.cpp
字号:
//我猜不出结果,没验证 恭喜中奖。
#include <iostream>
using namespace std;
#include <stdlib.h>
#include <process.h>
#include <cmath>
int ci=1;//全局
int guess(int x,int y)
{
int X,Y;
cout<<"请输入行号(0-9),列号(0-9):\n";
cin>>X>>Y;
if (x==X&&y==Y)
cout<<"恭喜你中奖了!\n";
else
{
int l;
int distance =sqrt((x-X)*(x-X)+(y-Y)*(y-Y));
cout<<"物体的大体位置距离你猜处大约"<<distance<<"个单位\n";
cout<<"再猜请按1 其他放弃 \n";
cin>>l;
if (l==1)
{
guess(x,y);
ci++;
}
return 0;
}
}
void main()
{ char game;
int s=1,x,y;
while(s)
{cout<<"S begin , T gameover\n";
cin>>game;
if(game == 'S')
{
cout<<"游戏开始:";
x = rand()%10;
y = rand()%10;
guess(x,y);
cout<<"您一共猜了 "<<ci<<"次\n";
}
else if (game == 'T') s=0;
else exit(1);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -