乘法函数给出一个恒定的随机数
multiplication function giving a constant random number
我是C++的初学者,我只是在学习函数。我的程序运行,但是,它给出了一个对我来说没有任何意义的常量数字。无论如何,这是我的代码,谢谢。
#include <iostream>
using namespace std;
int multiplication (int x , int s)
{
int v;
s=x*s;
return v;
}
int main (){
int u,k,l;
cout<<"enter two numbers"<<endl;
cin>>k;
cin>>l;
u = multiplication ( k , l);
cout <<"the result is "<<u<<endl;
return 0 ;
}
int multiplication (int x , int s)
{
int v;
s=x*s;
return v;
}
- 创建一个变量
v
。当前v
保存一个未初始化(不可预测)的值。 - 将
s
设置为乘法的结果。现在s
保存多属性的结果,v
仍然保存不可预测的值。 - 返回
v
的值(不可预测)。
你的意思是写return s;
,还是v=x*s;
?
相关文章:
- 如何在 c++ 中从数组中选择一个随机数?
- 从大范围内生成一个随机数,但从大范围的中间开始生成较小的范围
- 如何在C++中创建数字列表,以便它可以选择一个随机数?
- 在[0,1)C 之间生成一个随机数
- 在此过程中的纸牌游戏程序.不知道为什么我会得到一个随机数-858993460
- 为什么递增指针会给出一个随机数,而不是内存地址
- 如何使用Linux GetRandom系统调用来在范围内生成一个随机数
- visual如何在C++中创建一个随机数数组
- 选择一个随机方块并生成一个随机数
- 在一个间隔内生成一个随机数,但某些数字除外:EXC_BAD_ACCESS
- 当你复制一个随机数引擎和随机数分布时会发生什么?
- 给一个数组一个随机数
- 从整数列表中选择一个随机数
- 提供的示例代码返回一个随机数,即使在抛出异常之后也是如此(提供的代码)
- 如何使用openssl获得一个随机数
- 为什么在头文件的第一行放一个随机数
- C++和Qt:不要在x分钟内选择一个随机数
- 随机数生成器不会给我一个随机数
- 有没有一种方法可以让我从0-10亿中得到一个随机数
- 构造函数中变量的启动不起作用,而是给我一个随机数