using a function return

how do you use the value returned by a function in another function
crazy example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;

int a_function(int a)
{
	return a+1;
}

void b_function(int b)
{
	cout << "value of original var + 1 is " << b << endl;
}

int main(int argc, char ** argv)
{
	b_function(a_function(3));
	// or
	int f=1;
	f = a_function(f);
	b_function(f);
	return 0;
}
Last edited on
I cant make sense of this example I have a function that returns an int and I need to use that int in an if statement in the main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
int MyFunction()
{
   return 5; // Pointless function, returns 5 for sake of example
}

int main()
{
   if (MyFunction() == 5) // "If value returned from MyFunction equals five."
   {
      cout << "Hooray\n";
   }
   return 0;
}

// Alternatively, assign the results of that function to a variable
int main()
{
   int result = 0;

   result = MyFunction();

   if(result == 5)
   {
      cout << "Hooray\n";
   }
   return 0;
}
Last edited on
I fixed it I was using = instead of ==
Probably not the last time that one will get you. :-)
Topic archived. No new replies allowed.