Reputation: 23
I am a beginner in C++ and I was just learning about functions. My program runs, however, it gives a constant number that doesn't really make any sense to me. Anyway here is my code, thanks.
#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 ;
}
Upvotes: 2
Views: 233
Reputation: 58909
int multiplication (int x , int s)
{
int v;
s=x*s;
return v;
}
v
. Currently v
holds an uninitialized (unpredictable) value.s
to the result of the multiplication. Now s
holds the result of the muliplication, and v
still holds an unpredictable value.v
(which is unpredictable).Did you mean to write return s;
, or maybe v=x*s;
?
Upvotes: 3