First C++ Code

Clown Town

Senior Member
Joined
Jan 4, 2009
Posts
1,447
Bells
1,398
My VERY first C++ code... i am just starting to learn the language...

<div class='spoiler_toggle'>Spoiler: click to toggle</div><div class="spoiler" style="display:none;">#include <iostream>
using namespace std;
int main ()
{
int i,y;
y=2009;
cout << "I can predict what year you will die... what year you born? ";
cin >> i;
cout << "Here are your stats ";
cout << " Year Born : " << i;
cout << " Age : " << y-i;
cout << " Year of Estimated Death : " << i+80 << ".\n";
return 0;
}</div>


If anyone is having trouble understanding what it does PM me... but if you know what cout and cin are that should not be a problem...



One major error for no apparent reason... when running the EXE it skips everything after the first cin and closes :/ i can only get it to run in Visual C++

So... if you know how to use C++ can you tell me if this is a good first script?
 
My Schools IT teachers are starting to teach me this soon...

But think of it...

I am 14 years old... if i learn c++ by the age of 16-19 then the jobs i will be offerd :3
 
Very basic, but a start.

Just out of curiosity, what does
Code:
using namespace std;
do?
 
OddCrazyMe said:
Very basic, but a start.

Just out of curiosity, what does
Code:
using namespace std;
do?
i dont really understand what THAT in Particular does... i just know that the entire script wont work without it for some reason... i shall scour the tutorial i am using...
 
using namespace std;
All the elements of the standard C++ library are declared within what is called a namespace, the
namespace with the name std. So in order to access its functionality we declare with this expression that
we will be using these entities. This line is very frequent in C++ programs that use the standard library,
and in fact it will be included in most of the source codes included in these tutorials.
 
Java is a pain in the ass. If you're really wanting to start with something easy, just so that you can familiarize yourself with how code works, I'd suggest you start with Visual Basic.

@ Clown Town: I'm not quite sure exactly because I was using a school computer, and I generally don't code C++ on my home PC.
 
Back
Top