cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
The return operator doesn't return a val
The return operator doesn't return a value;
Apr 21, 2015 at 5:46am UTC
JMoriarti
(1)
Why can't I print the value of 's' with return.I don't want to do it with 'cout'.
#include <iostream>
using namespace std;
int s;
int surf(int a, int b)
{
s = a*b;
return s;
}
int main()
{
int x, y;
cin >> x;
cin >> y;
surf(x, y);
return 0;
}
Apr 21, 2015 at 6:16am UTC
Zhuge
(4664)
return
doesn't print anything; it does only what it says: returns the value. The problem, I think, it that you aren't doing anything with that returned value. You might want something like:
int
n = surf(x, y);
to store the returned value.
Topic archived. No new replies allowed.