PDA

Click to See Complete Forum and Search --> : what's wrong with the following code?


softwareguy74
Nov 16th, 2000, 11:03 AM
Hi,

I'm trying to learn VC++ and found an example excersice but it doesn't seem to work. Here is the code:


#include <iostream.h>

int main();
{
int x=5;
int y=7;
cout "\n";
cout << x + y << " " << x * y;
cout "\n";
return 0;
}


I get the following error when trying to compile the above .cpp file:

"error C2447: missing function header (old-style formal list?)"

Any ideas what this is and how to fix it?

Any help would be appreciated..

Dan

Vlatko
Nov 16th, 2000, 11:18 AM
Don't put ; after main() also cout "\n" is wrong. Use cout<<"\n"

#include <iostream.h>

int main()
{
int x=5;
int y=7;
cout<< "\n";
cout << x + y << " " << x * y;
cout<< "\n";
return 0;
}



[Edited by Vlatko on 11-16-2000 at 12:22 PM]

softwareguy74
Nov 16th, 2000, 11:30 AM
Thanks!

parksie
Nov 16th, 2000, 04:49 PM
Also, at the end of your program, you need to replace cout << "\n" with cout << endl.

What endl does is to add a newline, then flush the internal buffer. This ensures that all your data is displayed. However, it is slower so it should only be used every 20 lines or so.