unexpected end of file - extremly annoying!

Started by
4 comments, last by J e s t e r 22 years ago
With the code below Im getting an unexpeted end of file error. This happens quite alot and is getting rather annoying. The code is from a tutorial and I really want to know if I got the math problems right! Please help: Edit: Here's the error: Math.cpp c:\program files\microsoft visual studio\myprojects\math\math.cpp(102) : fatal error C1010: unexpected end of file while looking for precompiled header directive Error executing cl.exe. Math.exe - 1 error(s), 0 warning(s) code: #include <iostream> using namespace std; #define SHOW_ANSWERS 0 // If you want to see the answers printed to the screen // simply set this to 1, recompile and presto! int main() { int answer = 0; // This will hold our answer int x, y; // A couple variables we'll use // If we're not showing answers -- Spit out a message to that effect, quit the program if(SHOW_ANSWERS == 0) { cout << "Not showing answers now.\n"; return 0; } //************************************************************** Number 1 answer = 8 + 8 - 16 * 2; if(SHOW_ANSWERS) cout << "The answer equals " << answer << endl << endl; //************************************************************** Number 2 answer = (2 + (2 + 2 + (4 / 2 + 2) * 2) + 2); if(SHOW_ANSWERS) cout << "The answer equals " << answer << endl << endl; //************************************************************** Number 3 answer = 60 / 15 / 2 * 2; if(SHOW_ANSWERS) cout << "The answer equals " << answer << endl << endl; //************************************************************** Number 4 answer = 10 * 10 + 10 / 10 - 10; if(SHOW_ANSWERS) cout << "The answer equals " << answer << endl << endl; //************************************************************** Number 5 answer = 10 + 10 / 10 * 10 - 10; if(SHOW_ANSWERS) cout << "The answer equals " << answer << endl << endl; //************************************************************** Number 6 //******************* They are trickier from here on out **** x = 22; answer = x + 3 / (++x + 2); if(SHOW_ANSWERS) cout << "The answer equals " << answer << endl << endl; //************************************************************** Number 7 x = 5; y = 5; answer = (x + y) + (++y + ++x) / 2; if(SHOW_ANSWERS) cout << "The answer equals " << answer << endl << endl; //************************************************************** Number 8 x = 10; answer = x + (x + x--) + (x + x++); // The -- (postfix decrement operator) will // decrease x's value by one (in case you didn't know) if(SHOW_ANSWERS) cout << "The answer equals " << answer << endl << endl; //************************************************************** Number 9 x = 5; answer = (--x + 2) + (x-- + 2) * (x + 2) - (x + 2); if(SHOW_ANSWERS) cout << "The answer equals " << answer << endl << endl; //************************************************************** Number 10 y = 3; x = 5; answer = --y - (x + y) - x / 2 + (--x + 5) - y; if(SHOW_ANSWERS) cout << "The answer equals " << answer << endl << endl; return 0; // Program is over -- How did you do? // Be sure to look at the rules -- Look at the answers and be sure you know // how EVERY answer was arrived at } 12/32/84 Edited by - J e s t e r on March 29, 2002 6:24:04 PM
12/32/84
Advertisement

I copied exactly the code you provided but there are no errors under MSVC++6... either with SHOW_ANSWERS to 1. It''s not your fault!

I got this shitty error : it sometimes happens when you forgot a brace or a newline... really nasty!


I know that I don''t know nothing... Operation Ivy
I know that I don't know nothing... Operation Ivy
It compiles fine here:

The answer equals -16
The answer equals 16
The answer equals 4
The answer equals 91
The answer equals 10
The answer equals 23
The answer equals 16
The answer equals 50
The answer equals 36
The answer equals 0
Press any key to continue

Usually I get unexpected EOF''s when I forget some ''}'' (closing curly brackets).
Shabaz
I wander why Im getting the error? Im using MSVS 6..
12/32/84
You are getting this error because the compiler is
quote:Original post by Jester
looking for precompiled header directive
and can''t find it. Either put
#include "stdafx.h" 
on top of your .cpp file, or turn precompiled headers off or set them to auto.
---visit #directxdev on afternet <- not just for directx, despite the name
That worked

Thank you!
12/32/84

This topic is closed to new replies.

Advertisement