NOTE: You may download codes and extra source material for this book from https://bookofengineering.com/easyseries/
As we have seen in the previous section, library we are using for basic input / output operations is the iostream library. That is why we need to include that at the beginning.
From the previous section we saw that we can use “cout<<” to make it print the text you entered. Here will also start getting input.
Actually, that one is also very similar logic. To let user enter something to the program you need to enter “cin>>”.
The program below calculates the sum of the two integers entered;
- /*
- Program that gets sum of two integers entered by the user
- version 0.0
- author ilker <info@biawd.com>
- */
- #include <iostream> // include the input output library
- using namespace std;
- int main(){
- int firstNumber, secondNumber, sum;
- cout<<“Please enter the two integers to get the sum”;
- cin>>firstNumber>>secondNumber;
- sum = firstNumber + secondNumber;
- cout<<“Sum:”<<sum<<endl;
- return 0;
- system(“pause”);
- }
OUTPUT;
NOTE: You may buy this course in paperbook book format from https://www.amazon.com/dp/B0892HQTGS