Learning C++

10:38

C++ for basic

Next after the python programming language, we learnt about the other popular programming language which is C++. The C++ is more hard and require more understanding about the syntax compared to the python. Although C++ is more prone to be used as software builder, we also can use C++ for scientific calculations and input data. 

1. Important code.

In any C++ coding, we need to input three main element in the C++ which is

#include <iostream>
using namespace as std;
int main


Unlike python that use # to add comment, we need to add // only then the comment is valid. Then we need to add curly bracket to indicate the starting line of the body. In C++, the # is to add the library package. Then, we can start coding.But always bear in mind to put semicolon at the end of every line otherwise the code will not run.

2. Data types


For C++, we need to assign data types for every string. int stands for integer, use for whole numbers. double for numbers that have decimal place and char is used for single character in the word.

3. Input and output



Next, we use cout to display message in the terminal and cin for the user to input the data into terminal. Here is the example of the input an output. 


4. Data process 

Last but not least, we can display message and the C++ will do the calculations and show the data that we want only. Just use cout follow up with sentence that enclosed in " " and then the data. Then use return 0; to  set to run the program once only.   But every beginning must have an end, so we close our closing body with another end curly bracket. 
Then we can run our code, so it will looks like this.




You Might Also Like

0 comments

Contributors