C++ – How to Call Functions Within Another Function

c++

I am writing a program. And in the main function "int main()" i call to a function called, lets say, "int X()". Inside "int X()" I would like to call to another function "void Y()". Any ideas how to do this? I tried, inside the X() function, doing "Y();" and "void Y();" but to no prevail. Any tips on getting this to work? if at all possible?

ex.

#include<iostream>

int X()
{
   Y();
}

void Y()
{
   std::cout << "Hello";
}

int main()
{
   X();
   system("pause");
   return 0;
}

Best Answer

You must declare Y() before using it:

void Y();

int X()
{Y();}
Related Question