Dev C++/C++ - Basics
Posted: Wed Mar 16, 2011 2:43 pm
Hello and greetings everyone, in this thread I will be showing the basics in C++ while getting started.
I used Dev C++ for this tutorial.
Click here to download Dev C++
the basic hello world:
Cin and Integers and how they can be used:
Thanks for viewing my tutorial
I used Dev C++ for this tutorial.
Click here to download Dev C++
the basic hello world:
Code: Select all
NOTE: \n sign is a line break.//Hello World:
#include <iostream.h> //This is the header file, which tells the compiler what to include
using namespace std;
int main() //This is the start of the program(like Public Form1(); in C#)
{
cout<< "Hello world!" <<endl; //outputs the text
system("PAUSE"); //Tell's the program to paus
return(0); //Ends the programs code
}
Cin and Integers and how they can be used:
Code: Select all
Using doubles:
//Hello World:
#include <iostream.h> //This is the header file, which tells the compiler what to include
using namespace std;
int main() //This is the start of the program(like Public Form1(); in C#)
{
int num = 0; //This is an declared integer. It is important to keep the number at 0,
//as we ask the user to change it later in the program.
cout << "Please input a number:\n";
cin >> num; //This line is our input, where the user enters a number. Notice how the
//arrows are pointing right not left, as the output would.
cout << "The number is";
cout << num;
cout << "\n";
system("PAUSE");
return 0;
}
Code: Select all
If and Else statements:
//Hello World:
#include <iostream.h> //This is the header file, which tells the compiler what to include
using namespace std;
int main() //This is the start of the program(like Public Form1(); in C#)
{
double dnum = 0.0; //This has the same principals as the integer BUT
//it only deals with decimals where as integers deal with whole numbers.
//Note: Always remember to put the letter 'd' before your declared double code.
//For example:
//dnum
//This is so that in your code when you use that double it knows exactly that
//this is a double.
cout << "Please enter a decimal number:\n";
cin >> dnum;
cout << "The number is";
cout << dnum;
cout << "\n";
system("PAUSE");
return 0;
}
Code: Select all
Explained:
//Hello World:
#include <iostream.h> //This is the header file, which tells the compiler what to include
using namespace std;
int main() //This is the start of the program(like Public Form1(); in C#)
{
int num = 96;
if(num == 96){
cout << "Hello\n";
}
else{
cout <<"World";
}
system("PAUSE");
return 0;
}
Code: Select all
if (true){
//Execute these statements if TRUE
}
else{
//Execute these statements if FALSE
}
Thanks for viewing my tutorial
