添加随机数时遇到问题 [英] Having trouble adding random numbers

查看:59
本文介绍了添加随机数时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我正在制作一个数学辅导计划,它生成两个随机的
数字(从1到500)并要求用户添加它们。如何检查

以查看它们是否输入了正确的总数?你如何添加

无论如何生成的随机数?


#include< iostream>

#include< cstdlib>

#include< time>

#include< conio>

使用命名空间std;


int main()

{

未签名种子;


cout<< 输入种子值: ;

cin>种子;

srand(时间(0));

cout<< rand()%500<< endl;

cout<< rand()%500<< endl;

cout<< rand()%500 + rand()%500;

getch();

返回0;

}

输入种子值:1

385

425

644

解决方案

Naya写道:


嗨。我正在制作一个数学辅导计划,它生成两个随机的
数字(从1到500)并要求用户添加它们。如何检查

以查看它们是否输入了正确的总数?你如何添加

无论如何生成的随机数?



您需要将随机数存储在变量中。一旦他们存储了b $ b,他们就不再是随机的。




Naya < na *********** @ hotmail.comwrote in message

news:11 ******************* ***@q75g2000hsh.googlegr oups.com ...


嗨。我正在制作一个数学辅导计划,它生成两个随机的
数字(从1到500)并要求用户添加它们。如何检查

以查看它们是否输入了正确的总数?你如何添加

无论如何生成的随机数?



同样的方式你可以添加任意两个数字;它们来自哪里无关紧要。


int r(rand()+ rand());

-Mike


" Naya" < na *********** @ hotmail.comwrote in message

news:11 ******************* ***@q75g2000hsh.googlegr oups.com ...


嗨。我正在制作一个数学辅导计划,它生成两个随机的
数字(从1到500)并要求用户添加它们。如何检查

以查看它们是否输入了正确的总数?你如何添加

无论如何生成的随机数?


#include< iostream>

#include< cstdlib>

#include< time>

#include< conio>

使用命名空间std;


int main()

{

未签名种子;


cout<< 输入种子值: ;

cin>种子;

srand(时间(0));

cout<< rand()%500<< ENDL;



int Rand1 = rand()%500;

cout<< Rand1<<结束;


你应该能够从中找出其余部分。


cout<< rand()%500<< endl;

cout<< rand()%500 + rand()%500;

getch();

返回0;

}

输入种子值:1

385

425

644



Hi. I am working on a math tutoring program which generates two random
numbers (from 1 to 500) and asks the user to add them. How can I check
to see whether or not they put in the correct total?? How do you add
random numbers that are generated anyway??

#include <iostream>
#include <cstdlib>
#include <time>
#include <conio>
using namespace std;

int main()
{
unsigned seed;

cout << "Enter a seed value: " ;
cin >seed;
srand(time(0));
cout << rand()%500 << endl;
cout << rand()%500 << endl;
cout << rand()%500 + rand()%500;
getch();
return 0;
}
Enter a seed value: 1
385
425
644

解决方案

Naya wrote:

Hi. I am working on a math tutoring program which generates two random
numbers (from 1 to 500) and asks the user to add them. How can I check
to see whether or not they put in the correct total?? How do you add
random numbers that are generated anyway??

You need to store the random numbers in a variable. Once they are
stored, they''re no longer random.



"Naya" <na***********@hotmail.comwrote in message
news:11**********************@q75g2000hsh.googlegr oups.com...

Hi. I am working on a math tutoring program which generates two random
numbers (from 1 to 500) and asks the user to add them. How can I check
to see whether or not they put in the correct total?? How do you add
random numbers that are generated anyway??

Same way you''d add any two numbers; it doesn''t
matter where they came from.

int r(rand() + rand());

-Mike


"Naya" <na***********@hotmail.comwrote in message
news:11**********************@q75g2000hsh.googlegr oups.com...

Hi. I am working on a math tutoring program which generates two random
numbers (from 1 to 500) and asks the user to add them. How can I check
to see whether or not they put in the correct total?? How do you add
random numbers that are generated anyway??

#include <iostream>
#include <cstdlib>
#include <time>
#include <conio>
using namespace std;

int main()
{
unsigned seed;

cout << "Enter a seed value: " ;
cin >seed;
srand(time(0));
cout << rand()%500 << endl;

int Rand1 = rand() % 500;
cout << Rand1 << endl;

You should be able to figure out the rest from that.

cout << rand()%500 << endl;
cout << rand()%500 + rand()%500;
getch();
return 0;
}
Enter a seed value: 1
385
425
644



这篇关于添加随机数时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆