| | |
ERROR--Unexpected end to file
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
My main has an unexpected end to the file and i am having problems finding the error. can anyone help? It also says where "case 81" is that i already used it but I have not.
C++ Syntax (Toggle Plain Text)
void main () { HANDLE hOut; COORD NewSBSize; SMALL_RECT DisplayArea = {0, 0, 0, 0}; hOut = GetStdHandle(STD_OUTPUT_HANDLE); NewSBSize = GetLargestConsoleWindowSize(hOut); SetConsoleScreenBufferSize(hOut, NewSBSize); DisplayArea.Right = NewSBSize.X - 1; DisplayArea.Bottom = NewSBSize.Y - 1; SetConsoleWindowInfo(hOut, TRUE, &DisplayArea); HANDLE hConsole; int k; hConsole = GetStdHandle(STD_OUTPUT_HANDLE); for(k = 1; k < 2; k++) { SetConsoleTextAttribute(hConsole, 26); char keyPressed; bool quit = false; int dX; int dY; int dZ; do { system("cls"); cout <<endl; cout <<endl; for (int a = 0; a < 90; a++) cout << box; cout << endl; cout <<box <<" " << box << endl; cout <<box <<" " << box << endl; cout <<box <<" xxx__xxx_xx_xx____xx_xxxxx__xxxx__xx_______xx_xxxxx_xxxxx_xxxxx___xxxxx_xxxxxx_ " << box <<endl; cout <<box <<" xxx__xxx_xx_xxx___xx_xxxxx_xxxxxx_xx_______xx_xxxxx_xxxxx_xxxxxx__xxxxx_xxxxxxx "<< box <<endl; cout <<box <<" xxx__xxx_xx_xxx___xx_xx____xxx_xx_xx_______xx_xx____xx____xx___xx_xx____xx___xx "<< box <<endl; cout <<box <<" xx_xx_xx_xx_xxxx__xx_xx____xx______xx_____xx__xx____xx____xx___xx_xx____xx___xx "<< box <<endl; cout <<box <<" xx_xx_xx_xx_xx_xx_xx_xxxxx__xx_____xx__x__xx__xxxxx_xxxxx_xxxxxx__xxxxx_xxxxxx_ "<< box <<endl; cout <<box <<" xx____xx_xx_xx__xxxx_xxxxx___xx____xx__x__xx__xxxxx_xxxxx_xxx_____xxxxx_xxxx___ "<< box <<endl; cout <<box <<" xx____xx_xx_xx__xxxx_xx_______xx___xx_xxx_xx__xx____xx____xx______xx____xx_xx__ "<< box <<endl; cout <<box <<" xx____xx_xx_xx___xxx_xx____xx_xxx___xxx_xxx___xx____xx____xx______xx____xx__xx_ "<< box <<endl; cout <<box <<" xx____xx_xx_xx____xx_xxxxx_xxxxxx___xx___xx___xxxxx_xxxxx_xx______xxxxx_xx__xx_ "<< box <<endl; cout <<box <<" xx____xx_xx_xx____xx_xxxxx__xxxx____xx___xx___xxxxx_xxxxx_xx______xxxxx_xx__xx_ "<< box <<endl; cout <<box <<" " << box << endl; cout <<box <<" " << box << endl; for (int b = 0; b < 90; b++) cout << box; cout << endl; cout << endl; cout << endl; system("pause"); for (int d = 0; d < 90; d++) cout << box; cout << endl; cout <<box <<" " << box << endl; cout <<box <<" " << box << endl; cout <<box <<"Use ESC button to quit MINESWEEPER anytime" << box << endl; cout <<box <<"The arrow buttons on keyboard will move your player" << box << endl; cout <<box <<"Buttons < and > will be used to go up & down levels" << box << endl; cout <<box <<"Buttons = or - will increse/decrease the size" << box << endl; cout <<box <<" " << box << endl; cout <<box <<" " << box << endl; for (int e = 0; e < 90; e++) cout << box; cout << endl; system("pause"); for (int f = 0; f < 90; f++) cout << box; cout << endl; cout <<box <<" " << box << endl; cout <<box <<"Enter the number of rows you would like to have" << box <<endl; cout <<box <<" " << box << endl; for (int g = 0; g < 90; g++) cout << box; cout << endl; cout << endl; cout << endl; cin >> dX; while (dX > maxROW) { cout << "Please re-enter the number of rows that is less than that" << endl; cin >> dX; } while (dX < minROW) { cout << " Please re-enter the number of rows that is greater than that" << endl; cin >> dX; } for (int h = 0; h < 90; h++) cout << box; cout << endl; cout <<box <<" " << box << endl; cout <<box <<"Enter the number of columns you would like to have" << box << endl; cout <<box <<" " << box << endl; for (int i = 0; i < 90; i++) cout << box; cout << endl; cout << endl; cout << endl; cin >> dY; while (dY > maxCOL) { cout << "Please re-enter the number of columns that is less than that" << endl; cin >> dY; } while (dY < minCOL) { cout << "Please re-enter the number of columns that is greater than that" << endl; cin >> dY; } for (int j = 0; j < 90; j++) cout << box; cout << endl; cout<<endl; cout <<box <<"Enter the depth you would like to have" << box << endl; cout <<box <<" " << box << endl; for (int k = 0; k < 90; k++) cout << box; cout << endl; cout << endl; cout << endl; cin >> dZ; while (dZ > maxDEPTH) { cout << "Please re-enter the depth you would like that is less than that" << endl; cin >> dZ; } while (dZ < minDEPTH) { cout << "Please re-enter the depth you would like that is greater than that" << endl; cin >> dZ; } GridActive myGridActive (dX, dY, dZ); do{ myGridActive.setActive(myGridActive.getX(), myGridActive.getY(), myGridActive.getZ()); myGridActive.print ( myGridActive.getZ() ); myGridActive.printDimensions(myGridActive.getRow(), myGridActive.getCol(), myGridActive.getDepth()); char key; bool flag = false; key = getch(); switch (toascii(key)) { case 'Q': case 'q': quit = true; break; case 80: if (flag) { myGridActive.goSouth(); flag = false; } else cout << "try again. " << endl; break; case 72: if (flag) { myGridActive.goNorth(); flag = false; } else cout << "try again. " << endl; break; case 77: if (flag) { myGridActive.goWest(); flag = false; } else cout << "try again. " << endl; break; case 75: if (flag) { myGridActive.goEast(); flag = false; } else cout << "try again. " << endl; break; case 73: if (flag) { myGridActive.upsize(); flag = false; } else cout << "try again. " << endl; break; case 81: if (flag) { myGridActive.downsize(); flag = false; } else cout << "try again. " << endl; break; } while (!quit); cout << "\n Would u like to start over? Press key \n Would u like to quit? Press N "; keyPressed = getch (); quit = false; if (( keyPressed == 'N' ) || (keyPressed == 'n' )) quit = true; cin.get(); printEnd(); } }
Last edited by chubbywubba; Mar 6th, 2007 at 1:46 pm. Reason: forgot a question
you have mis-matched curly braces. The open brace on the do-loop is matched to the last close brace in the function. This is one reason I always place curly braces on lines by themselves so that they are easy to spot and match up. Some compilers IDEs and code editors, such as Microsoft VC++ and VI have macros that will show you the matching brace. Check you compiler's IDE to see if it has such a feature.
Last edited by Ancient Dragon; Mar 6th, 2007 at 2:33 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
C++ Syntax (Toggle Plain Text)
void main () { HANDLE hOut; COORD NewSBSize; SMALL_RECT DisplayArea = {0, 0, 0, 0}; hOut = GetStdHandle(STD_OUTPUT_HANDLE); NewSBSize = GetLargestConsoleWindowSize(hOut); SetConsoleScreenBufferSize(hOut, NewSBSize); DisplayArea.Right = NewSBSize.X - 1; DisplayArea.Bottom = NewSBSize.Y - 1; SetConsoleWindowInfo(hOut, TRUE, &DisplayArea); HANDLE hConsole; int k; hConsole = GetStdHandle(STD_OUTPUT_HANDLE); for(k = 1; k < 2; k++) { SetConsoleTextAttribute(hConsole, 26); char keyPressed; bool quit = false; int dX; int dY; int dZ; do { system("cls"); cout <<endl; cout <<endl; for (int a = 0; a < 90; a++) cout << box; cout << endl; cout <<box <<" " << box << endl; cout <<box <<" " << box << endl; cout <<box <<" xxx__xxx_xx_xx____xx_xxxxx__xxxx__xx_______xx_xxxxx_xxxxx_xxxxx___xxxxx_xxxxxx_ " << box <<endl; cout <<box <<" xxx__xxx_xx_xxx___xx_xxxxx_xxxxxx_xx_______xx_xxxxx_xxxxx_xxxxxx__xxxxx_xxxxxxx "<< box <<endl; cout <<box <<" xxx__xxx_xx_xxx___xx_xx____xxx_xx_xx_______xx_xx____xx____xx___xx_xx____xx___xx "<< box <<endl; cout <<box <<" xx_xx_xx_xx_xxxx__xx_xx____xx______xx_____xx__xx____xx____xx___xx_xx____xx___xx "<< box <<endl; cout <<box <<" xx_xx_xx_xx_xx_xx_xx_xxxxx__xx_____xx__x__xx__xxxxx_xxxxx_xxxxxx__xxxxx_xxxxxx_ "<< box <<endl; cout <<box <<" xx____xx_xx_xx__xxxx_xxxxx___xx____xx__x__xx__xxxxx_xxxxx_xxx_____xxxxx_xxxx___ "<< box <<endl; cout <<box <<" xx____xx_xx_xx__xxxx_xx_______xx___xx_xxx_xx__xx____xx____xx______xx____xx_xx__ "<< box <<endl; cout <<box <<" xx____xx_xx_xx___xxx_xx____xx_xxx___xxx_xxx___xx____xx____xx______xx____xx__xx_ "<< box <<endl; cout <<box <<" xx____xx_xx_xx____xx_xxxxx_xxxxxx___xx___xx___xxxxx_xxxxx_xx______xxxxx_xx__xx_ "<< box <<endl; cout <<box <<" xx____xx_xx_xx____xx_xxxxx__xxxx____xx___xx___xxxxx_xxxxx_xx______xxxxx_xx__xx_ "<< box <<endl; cout <<box <<" " << box << endl; cout <<box <<" " << box << endl; for (int b = 0; b < 90; b++) cout << box; cout << endl; cout << endl; cout << endl; system("pause"); for (int d = 0; d < 90; d++) cout << box; cout << endl; cout <<box <<" " << box << endl; cout <<box <<" " << box << endl; cout <<box <<"Use ESC button to quit MINESWEEPER anytime" << box << endl; cout <<box <<"The arrow buttons on keyboard will move your player" << box << endl; cout <<box <<"Buttons < and > will be used to go up & down levels" << box << endl; cout <<box <<"Buttons = or - will increse/decrease the size" << box << endl; cout <<box <<" " << box << endl; cout <<box <<" " << box << endl; for (int e = 0; e < 90; e++) cout << box; cout << endl; system("pause"); for (int f = 0; f < 90; f++) cout << box; cout << endl; cout <<box <<" " << box << endl; cout <<box <<"Enter the number of rows you would like to have" << box <<endl; cout <<box <<" " << box << endl; for (int g = 0; g < 90; g++) cout << box; cout << endl; cout << endl; cout << endl; cin >> dX; while (dX > maxROW) { cout << "Please re-enter the number of rows that is less than that" << endl; cin >> dX; } while (dX < minROW) { cout << " Please re-enter the number of rows that is greater than that" << endl; cin >> dX; } for (int h = 0; h < 90; h++) cout << box; cout << endl; cout <<box <<" " << box << endl; cout <<box <<"Enter the number of columns you would like to have" << box << endl; cout <<box <<" " << box << endl; for (int i = 0; i < 90; i++) cout << box; cout << endl; cout << endl; cout << endl; cin >> dY; while (dY > maxCOL) { cout << "Please re-enter the number of columns that is less than that" << endl; cin >> dY; } while (dY < minCOL) { cout << "Please re-enter the number of columns that is greater than that" << endl; cin >> dY; } for (int j = 0; j < 90; j++) cout << box; cout << endl; cout<<endl; cout <<box <<"Enter the depth you would like to have" << box << endl; cout <<box <<" " << box << endl; for (int k = 0; k < 90; k++) cout << box; cout << endl; cout << endl; cout << endl; cin >> dZ; while (dZ > maxDEPTH) { cout << "Please re-enter the depth you would like that is less than that" << endl; cin >> dZ; } while (dZ < minDEPTH) { cout << "Please re-enter the depth you would like that is greater than that" << endl; cin >> dZ; } GridActive myGridActive (dX, dY, dZ); do{ myGridActive.setActive(myGridActive.getX(), myGridActive.getY(), myGridActive.getZ()); myGridActive.print ( myGridActive.getZ() ); myGridActive.printDimensions(myGridActive.getRow(), myGridActive.getCol(), myGridActive.getDepth()); char key; bool flag = false; key = getch(); switch (toascii(key)) { case 'q': quit = true; break; case 80: if (flag) { myGridActive.goSouth(); flag = false; } else cout << "try again. " << endl; break; case 72: if (flag) { myGridActive.goNorth(); flag = false; } else cout << "try again. " << endl; break; case 77: if (flag) { myGridActive.goWest(); flag = false; } else cout << "try again. " << endl; break; case 75: if (flag) { myGridActive.goEast(); flag = false; } else cout << "try again. " << endl; break; case 73: if (flag) { myGridActive.upsize(); flag = false; } else cout << "try again. " << endl; break; case 81: if (flag) { myGridActive.downsize(); flag = false; } else cout << "try again. " << endl; break; } while (!quit); cout << "\n Would u like to start over? Press key \n Would u like to quit? Press N "; keyPressed = getch (); quit = false; if (( keyPressed == 'N' ) || (keyPressed == 'n' )) quit = true; cin.get(); printEnd(); } }
And they told me not use void main() but my teacher says we should. If the void main() and system("something") are bad coding how would i fix that or what else could i put?
Last edited by chubbywubba; Mar 6th, 2007 at 3:03 pm.
•
•
•
•
I fixed that now but I still have the un-expected file ending. Do you know why its doing this?
>>And they told me not use void main() but my teacher says we should
you need a different teacher because he/she doesn't know what he/she is talking about. void main has never ever been standard C or C++ syntax.
>>I looked for a bracket but I cannot find one missing
The program is missing two braces. One is the second do-loop is missing a close brace. I'm not certain where the other one is.
Suggestion: split your main() function into more than one function to keep the code short and easy for you to maintain, assuming you are allowed to do that. Your main() is just too big and unwieldly, and will give even most experienced programmers large head aches.
Last edited by Ancient Dragon; Mar 6th, 2007 at 6:21 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
> I looked for a bracket but I cannot find one missing.
Your main is over 200 lines long (and growing no doubt).
Moving some of the functionality into other functions will make things a lot clearer.
Press "Compile", and all is well
Press "Compile", and get a warning.
Lessons
1. by always typing in the { } in matched pairs BEFORE doing anything else, you never get into this problem of figuring out where the } should go to match the { you typed in yesterday.
2. by compiling often (ctrl-f7 and wait a couple of seconds) means you don't dig huge holes which take a long time to fix. If you only typed 5 lines since your last compile, then you've got a good idea where to look.
3. actually running the code every so often to make sure it's doing what it should is a good idea as well.
4. the always type the matching pairs applies to ( ), " " and /**/ as well. Sure it's a few extra cursor movements, but it sure cuts down on the confusion later on.
As experience grows, you can get away with typing more lines between compiles, but don't go beyond what you're prepared to deal with.
200+ lines and dump the whole lot on a message board definitely isn't the way to go.
Your main is over 200 lines long (and growing no doubt).
Moving some of the functionality into other functions will make things a lot clearer.
C++ Syntax (Toggle Plain Text)
for ( i = 0 ; i < 10 ; i++ ) { }
C++ Syntax (Toggle Plain Text)
for ( i = 0 ; i < 10 ; i++ ) { cout << "hello" << var << endl; }
Lessons
1. by always typing in the { } in matched pairs BEFORE doing anything else, you never get into this problem of figuring out where the } should go to match the { you typed in yesterday.
2. by compiling often (ctrl-f7 and wait a couple of seconds) means you don't dig huge holes which take a long time to fix. If you only typed 5 lines since your last compile, then you've got a good idea where to look.
3. actually running the code every so often to make sure it's doing what it should is a good idea as well.
4. the always type the matching pairs applies to ( ), " " and /**/ as well. Sure it's a few extra cursor movements, but it sure cuts down on the confusion later on.
As experience grows, you can get away with typing more lines between compiles, but don't go beyond what you're prepared to deal with.
200+ lines and dump the whole lot on a message board definitely isn't the way to go.
![]() |
Similar Threads
- warning:no newline at end of file (C)
- syntax error, unexpected $end in ndex.php on line 127 (PHP)
- bank system problem !!!! (C++ programming) (C++)
- C++ complete binary tree using an array. Unexpected end file (C++)
Other Threads in the C++ Forum
- Previous Thread: Guess what... I need help again
- Next Thread: jest started C++ i need some examples of combat systems for muds
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






