Jump to content
  • Advertisement
Sign in to follow this  
Doom-Box

Whats wrong here?

This topic is 4850 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I dont know whats wrong with my first program. Its written in C++ and its my very first program but I cant seem to find out what the problem is. I put everything in exactly like it says. //first program #include <iostream.h> int main() { cout << "Hello, World!\n"; return0; } I also noticed most ppl usually somehow put that into a code box. How do I do that on these forums?

Share this post


Link to post
Share on other sites
Advertisement
put in the line

using namespace std;

then look up about namespaces.


to do the code put it inbetween <source > < /source>

but replace '<' with brackets '['


IF that doesn't help, then tell us what the problem is. What errors etc..

Share this post


Link to post
Share on other sites
Dude im sorry I dont mean to sound more new to this than I am but. What the heck does that mean? The second part I understand and I thank you for it. But the first part (which I assume is talking about my code)I have no clue whatsoever your talking about.

Share this post


Link to post
Share on other sites
Well what errors are you getting?

Read the below and see if that helps.



//first program

#include <iostream> //don't put the .h at the end of the include file

using namespace std; //some identifiers are 'inside' a namespace.
//you must tell the compiler you are using that
//namespace so those identifiers will be in scope.
//cout is in the 'std' name space.
//the 'std' namespace is where all the C++ standard
//library identifiers are located.
int main()
{
cout << "Hello, World!\n";
return 0; // you need a space after the return
}


Share this post


Link to post
Share on other sites
i get these


C:\Dev-Cpp\Makefile.win [Build Error] [main.o] Error 1 (Each
undeclared identifier is reported only once for each function it appears in.)

18 C:\Dev-Cpp\main.cpp `return0' undeclared (first use this function)

C:\Dev-Cpp\main.cpp In function `int main()':

7 C:\Dev-Cpp\main.cpp previous declaration `int main(int, char**)' here

16 C:\Dev-Cpp\main.cpp declaration of C function `int main()' conflicts with

C:\Dev-Cpp\main.cpp In function `int main()':

Share this post


Link to post
Share on other sites
OK i was messing around with it a little bit and i have gotten rid of some of the errors now I have.




int main(0)
{
cout << "Hello, World!\n";
return0;
}



Share this post


Link to post
Share on other sites
the first error is the problem (i think)

return0 is unknown... but
return 0
is known by the compiler

you forget the space !!! ;-)

Share this post


Link to post
Share on other sites
You forgot a space between "return" and "0".

return0; // no
return 0; // yes

Also, change

int main ()

to

int main (int argc, char *argv[])

Share this post


Link to post
Share on other sites
First, get yourself a better tutorial. Whatever you're working from is at least six years out of date, which is an eternity in IT.

Second, fix the problem which indicated to me that the above was the case ;)


#include <iostream> // Proper C++ headers have no filename extension.
using namespace std; // These headers put their "stuff" (functions and global
// variables) into the 'std' "namespace", which prevents them from conflicting
// with any stuff you might make with the same name. We don't want to make
// anything called "cout", so we can use this line to tell the compiler "if
// something doesn't appear to be defined, look in the std namespace for it".
int main()
{
cout << "Hello, World!\n";
return 0;
}


Quote:
Original post by Doom-Box
i get these


C:\Dev-Cpp\Makefile.win [Build Error] [main.o] Error 1 (Each
undeclared identifier is reported only once for each function it appears in.)

18 C:\Dev-Cpp\main.cpp `return0' undeclared (first use this function)


"return0" doesn't mean anything to the compiler. "return" does, and "0" does. There needs to be a space in there.

Quote:

C:\Dev-Cpp\main.cpp In function `int main()':

7 C:\Dev-Cpp\main.cpp previous declaration `int main(int, char**)' here

16 C:\Dev-Cpp\main.cpp declaration of C function `int main()' conflicts with

C:\Dev-Cpp\main.cpp In function `int main()':


You have gotten two versions of the main() function in your file somehow. Either version is correct (with no parameters, or with the int and char** parameters), but you can only have one.

Share this post


Link to post
Share on other sites
i don't know how you are learning c, but if you want a good tut, here is a link (of course you can learn faster than written here !)

http://newdata.box.sk/bx/c/

How in this forum do you write links???? [url][/url] doesn't work...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!