![]() |
#2
yu4972722902014-09-03 23:09
|

#include<iostream>
#include<time.h>
using namespace std;//使用命名空间 std.
int main()
{
srand(time(NULL));//将时钟数作为随机数种子
int price,guess;
price = rand() % 1000 + 1;//取余,获得1~1000的随机数
cout << "please input the price:" << endl;
do{
cin >> guess;//记录玩家所输入数值
if(guess > price)
cout << "The price is lower than your guess,please input the price again:" << endl;
if(guess < price)
cout << "The price is higher than your guess,please input the price again:" << endl;//给予玩家比较大小的提示
}
while (guess != price);//循环结构
cout << "The price you give is right.It cost " << price << "." <<endl;//获得正确答案
system("pause");
return 0;
}
#include<time.h>
using namespace std;//使用命名空间 std.
int main()
{
srand(time(NULL));//将时钟数作为随机数种子
int price,guess;
price = rand() % 1000 + 1;//取余,获得1~1000的随机数
cout << "please input the price:" << endl;
do{
cin >> guess;//记录玩家所输入数值
if(guess > price)
cout << "The price is lower than your guess,please input the price again:" << endl;
if(guess < price)
cout << "The price is higher than your guess,please input the price again:" << endl;//给予玩家比较大小的提示
}
while (guess != price);//循环结构
cout << "The price you give is right.It cost " << price << "." <<endl;//获得正确答案
system("pause");
return 0;
}