TEA BREAK WITH C++: BASIC INPUT / OUTPUT

Bookmark

No account yet? Register

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; 

  1. /* 
  2. Program that gets sum of two integers entered by the user
  3. version 0.0
  4. author ilker <info@biawd.com>
  5. */
  6. #include <iostream> // include the input output library
  7. using namespace std; 
  8. int main(){
  9. int firstNumber, secondNumber, sum;
  10. cout<<“Please enter the two integers to get the sum”;
  11. cin>>firstNumber>>secondNumber;
  12. sum = firstNumber + secondNumber; 
  13. cout<<“Sum:”<<sum<<endl;
  14. return 0;
  15. system(“pause”);
  16. }

 OUTPUT;

NOTE: You may buy this course in paperbook book format from https://www.amazon.com/dp/B0892HQTGS

FavoriteLoadingAdd to favorites
Spread the love

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.