I don’t know why most beginners are afraid of C++. They say C++ is hard, but it really is not.
This should get you started.
C++ Info:
http://www.cplusplus.com/doc/tutorial/http://www.cplusplus.com/http://www.cppreference.com/http://en.wikipedia.org/wiki/C%2B%2Bhttp://www.research....om/~bs/C .htmlVisual Studio Express 2008 ( Compiler, IDE )
http://www.microsoft.com/express/vc/Short program with explatnation, by me:
Code#include <iostream>
using namespace std;
int main()
{
// Declare varibles
double number1;
double number2;
double result;
// prompt user for input
cout << "Enter number 1: ";
cin >> number1; // get number1
cout << "Enter number 2: ";
cin >> number2; // get number2
// calculate
result = number1 + number2;
// display result
cout << number1 << " + " << number2 << " = " << result << "\n";
// main must allway return something
return 0;
}
Explanation/* #include is used to include
a header file
in this case #include <iostream> includes the iostream.h
of standard library -- iostream provide input and output stream
in you program the default is the console window*/#include <iostream>
/*this will include the std namespace -- namespace is really an
advance part of C++ so i don't want to get into details
you should just know that if you dont't write this statement
you will have to say std::cout, std::cin, std::end,...*/using namespace std;
/* main is the main entrance to you program -- this is where your
program will start executing all C++ program must have one and only
one main funtion and main must return an int */int main()
{
/* As you can see this is how you declare a variable datetype
folllowed by an identifier. In this tutorial i used the double datatype.
Here are some more data type: void, int, char, float.
Read a book to learn about Modifiers ( unsigned, signed, long, short )*/ // Declare varibles
double number1;
double number2;
double result;
/* cout is an object of class ostream. cout is used to display text to
the console. Notice that you use the << , extraction operator, to display text */ // prompt user for input
cout << "Enter number 1: ";
/* cin is an object of class istream. cin is used to retrive input from keyboard.
Notice that you use >> , called , insertion operator to get input.*/ cin >> number1; // get number1
cout << "Enter number 2: ";
cin >> number2; // get number2
/* this works just like algebra math, = assigns what ever is in the
right to the varialbe on the left*/ // calculate
result = number1 + number2;
/* Notice how i use the insertion operator ( << ) THIS TIME */ // display result
cout << number1 << " + " << number2 << " = " << result << "\n";
return 0;
}