Hi, this is Chris, and I was hoping that you guys could supply me with the code (yah, I know that you guys don't do homework, but this is an exception? :D) for making a simple "Hello World" program? Even one that asks answers of the user (for example, "Whats your name?" then, with cin I use it later? I can do this, but my book is totally out-dated, so I can't use it on the C++ program I have now (Dev-C++)).
In advance, thanks guys.:@

>I was hoping that you guys could supply me with the code
We can, but that doesn't mean we will.

>I know that you guys don't do homework, but this is an exception?
Nope.

>I can do this, but my book is totally out-dated
Get a new one. Or use one of the many-available online tutorials, such as this one.

Or you could just give us the code that's "outdated", and we'll tell you what's wrong with it. (most likely it's using iostream.h instead of iostream, or worse, using void main instead of int main)

alright. heres the code, I will do some tutorials now, and . . . Book? Sometime, maybe... Not sure how into C++ i am, it's just a hobby. We'll see

#include <iostream.h>
 
int main()
{
       int name;
       cout << "Hello World!/n";
       cout << "Whats your name?: ";
       cin >> name;
       cout << "Oh, so your name is " << c;
       cout << "Thanks for reading, folks...";
       return 0;
}

> #include <iostream.h> Change this to

#include <iostream>
using namespace std;

> int name; Oh, so I suppose that nowadays names consist purely of numbers? If you actually do want to store some letters, try using string instead, but you might have to include <string>.

> cout << "Oh, so your name is " << c; This is strange... why in the world do you print out 'c' when you just stored the user's name in name ??

And the list carries on... did you write that yourself, or did you get that from somewhere? Why not just work your way through cprogramming's tutorials until you're fairly comfortable with the C++ programming language?

well, for the 'c' thing, I had it as 'c' in the first place, wrote the code, then was like "C is confusing, may as well make it name"
true, the thing has changed (or always was) string.
cool. and also the header thing, got that down too now. Thanks!

I have one final problem, although it might have been related to the things that I've changed above. I dont have my C++ on this computer right now. When I ask a question that (after this) gets 'cin'ned, the window shuts down after you type enter. Why?

>When I ask a question that (after this) gets 'cin'ned, the window shuts down after you type enter.
Basically Windows closes console applications when the execution is finished. You can fix this problem by pausing the application before it closes by using something like this:

// clear any errors
cin.clear();

// flush the input buffer
cin.ignore(numeric_limits<streamsize>::max, '\n');

// pause the program
cin.get();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.