我正在尝试编写一个使用种子生成伪随机数的程序。但是,我遇到了问题。
我收到这个错误
39 C:\Dev-Cpp\srand_prg.cpp void value not ignored as it ought to be
使用此代码
#include <iostream>
#include <iomanip>
#include <sstream>
#include <limits>
#include <stdio.h>
using namespace std ;
int main(){
int rand_int;
string close ;
close == "y" ;
cout << endl << endl ;
cout << "\t ___________________________________" << endl ;
cout << "\t| |" << endl ;
cout << "\t| Pseudorandom Number Game! |" << endl ;
cout << "\t|___________________________________|" << endl ;
cout << endl << endl ;
while ( close != "y" ){
rand_int = srand(9);
cout << rand_int << endl ;
cout << " Do you wish to exit the program? [y/n] " ;
cin >> close ; }
}
srand
不返回随机数,它只是重新播种随机数生成器。称呼rand
之后实际得到一个数字:
srand(9);
rand_int = rand();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)