这个是第二个程式码
因为我觉得还满简单的,所以我就没写注解了
另外,你的题目有点看不懂,所以我写的可能跟你要的不一样
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
srand(time(0)); //产生乱数种子
int y;
y=rand()%100;
int min=0,max=100,guess;
int time=0;
char try_again;
do
{
cout << "*************************" << endl;
cout << " c++ 猜数字游戏 " << endl;
cout << "*************************" << endl;
cout << "\n";
cout << "输入数字 : ";
cin >> guess;
if(guess == y)
{
cout << "一次就答对了 !!" << endl;
cout << "Try again ?(y/n) ";
cin >> try_again;
}
else
{
cout << "再输入一次" << endl;
int i=0;
for(i=0;i>=0;i++)
{
cout << "输入数字 : ";
cin >> guess;
if(guess == y)
break;
else
{
if(guess > y)
{
cout << "小一点" << endl;
if(guess < max)
max=guess;
}
else if(guess < y)
{
cout << "大一点" << endl;
if(guess > min)
min=guess;
}
cout << "介于" << min << "和" << max << "之间" << endl;
}
}
cout << "你总共输入" << i+2 << "次" << endl;
cout << "Try again ?(y/n)";
cin >> try_again;
}
}while(try_again == 'Y' || try_again == 'y');
system("pause");
return 0;
}