main() "doesn't exists" - can't return
Apr 21, 2012 at 9:32pm UTC
Hi everyone, i'm a beginner in C++ and wanted to create something very simple...
Now my compiler tells me that he can't return from int exit(); to int main(); because it "wasn't found".
May you can search the code for an error i made. The web didn't offered any useful answers to me...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
#include <iostream>
#include <conio.h>
#include <string>
#include <cstdlib>
#include <stdlib.h>
#include <windows.h>
using namespace std;
[...]
int exit() {
char cExit;
cout << "Do you really want to exit the application? Y/N" << endl;
cin >> cExit;
if (cExit == 'Y' || 'y' ) {
return 0;
}
else if (cExit == 'N' || 'n' ) {
system("CLS" );
return main();
}
else {
system("CLS" );
return exit();
}
return 0;
}
int main() {
int iMenuChoice;
cout << " Welcome to the Game" << endl << endl;
Sleep (1000);
cout << "1. New Game" << endl;
Sleep (800);
cout << "2. Instructions" << endl;
Sleep (800);
cout << "3. Options" << endl;
Sleep (800);
cout << "4. Exit" << endl;
Sleep(800);
cout << "Type in the Number of the Submenu you want to visit: " ;
cin >> iMenuChoice;
if (iMenuChoice == 1) {
system("CLS" );
return game();
}
else if (iMenuChoice == 2) {
system("CLS" );
return instructions ();
}
else if (iMenuChoice == 3) {
system("CLS" );
return options();
}
else if (iMenuChoice == 4) {
system("CLS" );
return exit();
}
else {
cout << "Operation unknown" ;
_getch();
system("CLS" );
return main();
}
return 0;
}
Thanks in Advance!
Apr 21, 2012 at 9:48pm UTC
A program is not allowed to call the main() function don't do it. If you want to call a function before it has been defined you have to declare it before using it.
Topic archived. No new replies allowed.