Learn to make a simple program in C++.
Hello, welcome to Basic C++ Lesson. C++ has many uses which you can learn later when you become and experienced programmer. To start off your C++ learning experience you will need a program that will help make your coding work. It is free and very useful for beginners here is the link . . . .
Open up the program we are almost to the coding part. But first we have to change the options a little bit.
Step 1. Choose Tools on the top bar.
Step 2. Choose Compiler Options in the tool drop down menu.
Step 3. Click on the Settings tab.
Step 4. On the left hand side choose Code Generation.
Step 5. Make sure Enable Exception Handling is yes.
Step 6. Click on Linker on the left hand bar.
Step 7. Make sure Generate Debugging Information is yes.
That is it for setting it up. Now you get to make your first C++ program.
Okay this program is going to be short and simple. Go to file -> New -> Source File. This will let you start your first C++ program.
Okay you need to set up your header file which is very simple when making simple programs.
Type this into the space and don’t worry about spacing or lines the computer ignores the spacing it is just easier to see this way.
#include
using namespace std;
int main()
{
system(”PAUSE”);
}
Okay now you’re just confused what does all this mean? I’ll break it down line by line. Don’t worry about #include that gets into more advance stuff.
using namespace std. Lets your computer know that this program will display something on the screen.
int main() {} int main is saying that you are going to start typing the program specifics. The two curly brackets tell were your program will begin and end. It is called the main function.
system(”PAUSE”); Tells the computer to pause the screen and don’t immediately close the window. Also note the semicolon at the end, this is like a period in regular language the semicolon tells when you are done with one line of code and going to another.
Okay so know you have a program that does nothing at all well that is not very fun is it so let’s add something to it to make it more interesting.
In your main function between the to {} but before the system(”PAUSE”) type in
cout << “__________”;
Go click on Execute -> compile and run.
Now a little window called the console will pop up showing whatever you type in between the quotes.
You can add things to the end of your cout things like endl will end the line try putting it in your program like this.
cout << “Words go here” << endl;
see the difference don’t forget that ending semicolon.
Now time to learn about number in programing. Please bring up this program starter.
#include
using namespace std;
int main()
{
system(”PAUSE”);
}
To start off using numbers you have to declare a variable. Yeah well that sound real confusing, what it means it make a word or letter that is equal to a number. To declare a variable is simple just type one of the fallowing codes. Remember to always put semicolons at the end or the statement.
int int is used for counting number (ex. 1, 2, 3 etc.)
float float is a number and decimal but does not use a lot of decimals (ex. 1.5, 3.56, 2.75 etc.)
double double is like float but it decimal will go on and on and on (ex. 6.323523343223444 lots of decimals)
So to declare your variable you would go into the main function and type
int variable; were it says variable you can name it whatever you want. (ex float total; double num; etc.)
If you want to type in multiple variables at the same time put a comma in between ex. int x, y, z;
Now you have your variable let’s make that variable hold a number. The first way to do it is just strait forward. After declaring your variable type
variable = 5; Were I put variable put what you put and you can do any number that fallows the rules of whichever code you used to declare it make sure you have already declared the variable.
The second way is to take a user input when the program is already opened the user can input a value for the variable. You can set this up by typing.
cin >> variable;
cin >> lets you take an input and put the number into your variable.
Now here is the ability that become most useful doing math to your numbers.
* Makes multiplication.
/ Makes division.
- Makes subtraction.
+ Makes Addition.
You can use these arithmetic symbols on variables as well and you can include multiple variables in one equation. To view the numbers during the program you just simply type
cout << variable;
and your variable’s value will be displayed during the program.
I’m going to give an example program to show what you can do.
#include
using namespace std;
int main()
{
int numa, numb, total;
cout << “Please enter value a”;
cin >> numa;
cout << “Please enter value b”;
cin >> numb;
total = numa + numb;
cout << total;
system(”PAUSE”);
}
In this program you see me declare 3 variables numa, numb, and total. Then you see me make the message “Please enter value a” and then cin >> numa takes the number inputted and saves it into the variable. The same thing is done to numb. Then I add numa and numb together and I get the total which then I display on the screen.
Now I want you to play around with this basic information and start making our own simple programs. Please support the site and the advertisements so that I can make a second were you will learn to make more complex programs. Just keep playing around making things that add and divide until you understand everything.










Leave Your Response