On line 9 in the previous example we give
int firstNumber, secondNumber, sum;
We define integer variables. These are first number with the definition firstNumber, and the second number defined as secondNumber. And the sum. These we defined as integer by writing “int” at the beginning.
On line 11;
We wait for the user to enter first and second number. And if user enters a number and press enter, at first time, the number is assigned to the firstNumber variable. And after that the program waits once more to wait for the user to enter a number. And if the user enters the number and press enter, this line of code is finished. The program assigns the number entered by the user to the secondNumber variable.
- Here a quick note: the naming principle we used here by giving the first variable name as “firstNumber” is called camel case. Actually, there is another type of naming, with underscore. Like first_number. These two are very popular among coders and traditional.
On line 12;
sum = firstNumber + secondNumber;
Here we do the calculation. Here the program adds two numbers and assigns the result to the “sum” variable we defined previously.
On line 13;
We print first “sum:” and then we print variable we named as sum. And at last we end the line and start a new line by the code “endl”.
So, if you add in any line “cout<<endl” it means program need to end this line and start a new one.
NOTE: You may download codes and extra source material for this book from https://bookofengineering.com/easyseries/
NOTE: You may buy this course in paperbook book format from https://www.amazon.com/dp/B0892HQTGS