Please I need help

Jan 23, 2013 at 4:04pm
Please help

I have this book programming for dummies and they gave a code I want to make sure the code is good and how do I see it on screen here is the code:
#include <iostream>
#include <stdio.h>
int main ()
{
cout << "It works!\n";
cout << "\nPress ENTER to contiune..." << endl;
getchar();
return 0;
}

Am I writing it right and what button do I push to see it and and is the code right??? I have no idea how to see what I wrote what do I press so new to this and I am scared.
Jan 23, 2013 at 4:29pm
..are ya using a compiler? can you click build?

did you receive any sort of documentation with your software?

btw the code itself looks solid, although I rarely mess with stdio.h.. if you remove "#include <stdio.h>" and "getchar();" you may find it still does what you want on execution.
Jan 23, 2013 at 4:35pm
I am using Dev C++ it came with the Programming for Dummies.
Jan 23, 2013 at 4:38pm
So.. open the dev program, go to new, start a new project, and create a new source file, put the code in there and click build, then run.
Jan 23, 2013 at 4:42pm
It says source file not complied after hitting run and I dont see a build button anywhere.
Jan 23, 2013 at 4:50pm
there's gotta be a build or compile button.. on mine it's right next to run. do you have an active workspace open?
Jan 23, 2013 at 4:56pm
I hit it and it is not letting me, they are saying line number 5
5 C:\Users\\Desktop\Seeifworks.cpp `cout' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)
6 C:\Users\\Desktop\Seeifworks.cpp `endl' undeclared (first use this function)

I have no idea what this means and do I need a new complier?
Jan 23, 2013 at 5:04pm
ah no
try inserting this statement right after your # command lines

using namespace std;

see what is says then
Jan 23, 2013 at 5:07pm
also if you get rid of "getchar();" (which i swear you may not need)
and replace these two lines:

cout << "It works!\n";
cout << "\nPress ENTER to contiune..." << endl;

with this one:

cout << "It works!\n\nPress ENTER to continue\n";

should be equivalent and then you won't need to include #include <stdio.h>
Jan 23, 2013 at 5:08pm
No good at all, I need a new baking sheet or a place to put this code down, a complier, do you know any that are free? Because it is because of that!
Jan 23, 2013 at 5:13pm
hmm. it really should work if all the include and header files are in the right place.. could ya post the code with "using namespace std;" included and exactly what the errors are when you try to compile. Here's what i'd try.

#include <iostream>
using namespace std;
int main()
{
cout << "It works!\n\nPress ENTER to continue\n";
return 0;
}

if it won't compile that code exactly then yeah you've got a problem with something else
Jan 23, 2013 at 5:14pm
and if there's a free compiler out there let me know lol I'd love to have it I am using educational version but can't legally distribute the executables developed with it
Jan 23, 2013 at 5:14pm
It works I wish they would have placed that before and Thank you very much!!!
Jan 23, 2013 at 5:17pm
glad to be helpful :3 yeah I totally had issues with my compiler at first.. I'll keep checkin this topic in case ya run into something else
Jan 23, 2013 at 5:25pm
Btw one last thing:

What does:

using namespace std;


mean????
Jan 23, 2013 at 5:39pm
my understanding is it tells the compiler to reference elements from the c++ std library.. Some people don't use it, instead prefixing certain statements with std:: (e.g: "std::cout << string;" instead of "using namespace std; cout << string;")
however, if you use cin, cout, and other std library entities more than once or twice in your program, it makes the code look kinda bleh to me, so just use:
"using namespace std;" and you won't have to worry about saying "std::" before everything
hope that made sense lol I don't know that much about it
Jan 23, 2013 at 5:58pm
You know more than me and I am more of a noob but all good we all have to start somewhere to be princes of the universe :-D
Topic archived. No new replies allowed.