My C++ Tutorials - Functions
Using More Than One Function:
Finally some advanced stuff...about time I bet. In this example we take a look at a new version of the hello world application. This time instead of performing the task of printing text onto the screen within the main fucntion, we will now be performing that task within a new function called callme. Take a look at the example below to get an idea of just how simple this is.
#include "stdafx.h"
#include "iostream.h"
//declare new function here
void callme(int);
int main(int argc, char* argv[])
{
int x;
x=1;
//call new function here
callme(x);
return 0;
}
void callme(int a)
{
int b = a;
while (b < 10){
if (b > 5)
{
printf("Hello World!\n");
}
else if (b < 5)
{
cout << "Hello out there!!\n";
}
b++;
}
cout << "Hello out there!!\n";
//return 0;
}