-
Ahhh functions!!! helpz
Code:
#include <iostream>
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <ctype.h>
using namespace std;
int main(int argc, char *argv[])
{
char choice;
printf("\n");
Sleep(100);
printf("\n");
Sleep(100);
printf("\n");
Sleep(100);
printf("\t\t\t By Me\n");
Sleep(100);
printf("\n");
Sleep(100);
putchar('\n');
Sleep(100);
printf("\t\t\t [N]ew Game\n");
printf("\t\t\t [Q]uit\n");
Sleep(100);
printf("\n");
Sleep(100);
printf("\n");
choice=toupper(getch());
for(;;)
{
if(choice=='N')
{
game();
break;
}
if(choice=='Q')
{
break;
}
}
return 0;
}
For some reason it keeps telling me that game is undeclared this is a dev project file btw,
I named the file game and the function in the file is called game i added the file to the project i dont under stand why it is not working
-
game(); looks like a call to a function to the compiler. You do not have a function named game declared in that code. If you are trying to link it in from another file you have to include it like you did so many other things at the top. There is also room to improve your printf and sleeps.
Search cout for some ideas. If you feel you 'must' have all of those sleeps, blank lines etc, remember this:
Any time you type the same thing over and over in your code, there is probably a shorter way.
-
Where's "game()" declaration?...that should be the problem...and why u use for(;;) for that?...just use and if, else sentence.
-
I see my example didn't do you any good.
Oh, well...
Soma
-
As ive said its a project file everything is their its just saying its undeclared and i tried using #include <game> but that isnt going to work concidering then id have to put game in the folder were headers go
-
if you have made your own header like:
game.h
Code:
#ifndef GAME_H
#define GAME_H
game(); // whatever the return type and parameters are
#endif
You have to include it in main like so:
Headers with < > are compiler pre-defined library files. Quoted names " " are programmer defined.