这次是C++问题。C++存储两个随机数的乘积
我试图在两个随机数之间存储产品......它应该是问什么两个随机数之间产生的基于srand(time(0))生成的,并且输入-1后退出...
下面是我的代码:
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <iomanip>
using std::setw;
#include <cstdlib>
using std::rand;
using std::srand;
#include <ctime>
using std::time;
int multiplication()
{
srand(time(0));
int x = 0;
while (x != -1)
{
int random_int;
random_int = (rand()%10 * rand()%10);
cout << "(Enter -1 to quit) \n";
cout << "" << rand() % 10 << " multiplied by " << rand() % 10 <<"? \n";
cin >> x;
if(x == random_int)
{
cout << "you're right!" << endl;
}
else
{
cout << "you're wrong" << endl;
}
}
return 0;
}
int main()
{
multiplication();
}
问题在哪里? –