Code Check Please. Syntax Errors

I'm completely new to programming of any sort, and am halfway through my second day of trying to learn C++ using a beginners guide that Microsoft's Visual C++ 2008 Express Edition linked to.

The code in the guide is the exact code I'm attempting to compile, but I keep getting the same syntax errors.


Code:

/* Project 1-2
This program displays a conversion table of feet to meters
*/

#include <iostream>
using namespace.std

int main()
{
double f; // Holds the length in feet
double m; // Holds the conversion in meters
int counter;

counter = 0; // Line counter is initially set to zero

for(f = 1.0; f <= 100.0; f++) {
m = f / 3.28; // converts to feet
cout << f << " feet is " << m << " meters.\n";

counter++;

// every 10th line print a blank line
if(counter == 10) {
cout << "\n"; // output a blank line
counter = 0; // reset the line counter
}
}

return 0;

}

The syntax errors:

ftomtable.cpp(6) : error C2059: syntax error : '.'
ftomtable.cpp(9) : error C2143: syntax error : missing ';' before '{'
ftomtable.cpp(9) : error C2447: '{' : missing function header (old-style formal
list?)


I've tried looking for solutions on the web as well as the forums here, but I just can't seem to find what I'm looking for. I solved an error in a previous program by simply copying my code and pasting it in a new file and then compiling it like normal, but that didn't work for this program. As near as I can tell, I'm using the exact code that's in the guide, so I don't know if maybe the guide had a typo perhaps.

I would really like someone to look at the code and tell me if they see any errors in the way it's typed out...

Using Visual C++ 2008 Express Edition on a Windows Vista (64) computer.
Compiling from the command line using "Visual Studio 2008 Command Prompt"
Last edited on
Ok, first of all.... your return 0 has a colon instead of a semicolon. :D

second problem is at your namespace
make it
using namespace std;

i dont know about the last error unless fixing those two errors fixes that one :D
Last edited on
Thank you so much.... I do feel like a complete idiot for not noticing either of those errors. Been stumped for hours now searching and reading all over the web. I did notice the "return 0:" mistake and tried to re-compile, but that had no effect on the error messages. Then right after editing this post I saw your reply. Thanks again, I really appreciate your help...
for(f = 1.0; f <= 100.0; f++) {

Doesn't this give you an error?

You can't use ++ or -- with floating point values. Change to f += 1
Last edited on
Nope, I have recompiled the program after fixing both mistakes (namespace std; and return 0;) and the program executes as advertised. The only error I get is:

C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\INCLUDE\xlocale(342) : war
ning C4530: C++ exception handler used, but unwind semantics are not enabled. Sp
ecify /EHsc

But I get that exact same warning no matter what program I try to compile.
no problem! :D

that error you're talking about its a warning..... ur program should still run fine... :/
Hrm... I just tried to increment a floating point and I don't get an error in GCC either.

Weird! I totally thought it was illegal.
Topic archived. No new replies allowed.