well, if you still want to continue like that,
you need to declare the function name again at the bottom, after main()
become something like...
» Click to show Spoiler - click again to hide... «
#include<stdio.h>
void playgame();
void loadgame();
void multiplayer();
int main()
{
int input;
printf("1) Play game\n");
printf("2) Load game\n");
printf("3) Multiplayer\n");
printf("4) Exit\n");
printf("Selection: ");
scanf("%d", &input);
switch (input)
{
case 1:
playgame();
break;
case 2:
loadgame();
break;
case 3:
multiplayer();
break;
case 4:
printf("Thanks for playing!\n");
break;
default:
printf("Invalid input, PC is restarting...\n");
break;
}
getchar();
}
void playgame() {codes here....};
void loadgame() {codes here....};
void multiplayer() {codes here.};
like this then can only compile., the three function above is so that you no need to consider the function order being declared.
because sometimes you call function B inside a function A, but the function B is below function B, hence hasn't been declared and can't be used.
this one can not compile
» Click to show Spoiler - click again to hide... «
#include <iostream>
using namespace std;
void A()
{
B();
}
void B()
{
cout << "A";
}
int main ()
{
A();
return 0;
}
but this one can, because B() has been declared first, then A() can call B().
» Click to show Spoiler - click again to hide... «
#include <iostream>
using namespace std;
void B()
{
cout << "A";
}
void A()
{
B();
}
int main ()
{
A();
return 0;
}
else, if you don't want to mess with the order, can just declare the name, and make the code function at below main()
» Click to show Spoiler - click again to hide... «
#include <iostream>
using namespace std;
void A();
void B();
int main ()
{
A();
return 0;
}
void A()
{
B();
}
void B()
{
cout << "A";
}