Results 1 to 4 of 4

Thread: what's wrong with the following code?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091
    Hi,

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

    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

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Don't put ; after main() also cout "\n" is wrong. Use cout<<"\n"
    Code:
    #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]
    I am become death, the destroyer of worlds.
    mail:vlatkovr@hotmail.com

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091
    Thanks!

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width