随机数函数应用于游戏

问题及代码:
copyright(c++).烟台大学计算机与控制工程学院
文件名称:默认函数
作者:马艳艳
完成日期:2016年3月24日
版本号:vc++6.0
问题描述:随机产生一个1000内的数字,要求用户猜测这个整数。输入一个猜测想的整数,判断是否与产生的随机数相同。
输入描述:输入一个猜测想的整数。
输出描述:比对结果;
#include<iostream>
#include<stdlib.h>
using namespace std;
int main()
{
	int t;
	int num;
	int seed;
	cout<<"please enter an unsigned integer "<<endl;
	cin>>seed;
	srand(seed);
	t=rand();
	cout<<"please enter a number you want to input"<<endl;
	cin>>num;
	cout<<t<<endl;
	if(num==t)
		cout<<"相等"<<endl;
	else if(num<t)
		cout<<"小了"<<endl;
	else
		cout<<"大了"<<endl;
return 0;
}

运行结果:

随机数函数应用于游戏_第1张图片

知识点总结:

学会运用srand函数,而且还知道它的类型。收获很大;

学习心得:

太令人兴奋了,天呐,我感觉很神奇哎,又是一个新知识点希望自己能熟练运用,参透精华。

你可能感兴趣的:(C++,函数,vc++6.0)