i have declared two functions of void type.lets one function calculates value of variable 'c' and other of variable 'y' and when i cout them it comes out to be correct within the function.now i want to declare another function that compares values of 'c' and 'y' and return 1 if c=y and return 0 otherwise.please help and also i m a beginner in c++.

4 Years
Discussion Span
Last Post by panqnik

Change the return type of each function to return the value of c and y, then in the third function you can get those values to compare them. Something like this:

int foo1()
   int c = 5;
   return c;

int foo2()
   int y = 0;
   return y;

int foo3()
   int c = foo1();
   int y = foo2();
   return c == y;  // returns either 1 or 0 (true or false)

Edited by Ancient Dragon


return 1 if c=y and return 0 otherwise

for this , you need to declare a function of int return type.

function that compares values of 'c' and 'y'

just use == operator.

return 1;
return 0;

Edited by Learner010: AD Solution is far better. i didn't see the AD's reply when i read this thread.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.