| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 837 人关注过本帖
标题:C++ 中有关 srand 我这个为什么在 Dev-c++ 里面不能运行? VC 就能运行?
取消只看楼主 加入收藏
yu497272290
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2013-11-2
结帖率:42.86%
收藏
 问题点数:0 回复次数:2 
C++ 中有关 srand 我这个为什么在 Dev-c++ 里面不能运行? VC 就能运行?
程序代码:
#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;

 
}
搜索更多相关主题的帖子: price guess 
2014-09-03 23:04
yu497272290
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2013-11-2
收藏
得分:0 
?有人在吗?问一下
2014-09-03 23:09
yu497272290
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2013-11-2
收藏
得分:0 
加上
#include <stdlib.h>

我前几天和你一样
2014-09-06 15:31
快速回复:C++ 中有关 srand 我这个为什么在 Dev-c++ 里面不能运行? VC 就能运 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020303 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved