Computer Programming 1 - Module 2
Computer Programming 1 - Module 2
Module #2
Productivity Tip:
“Successful and unsuccessful people do not vary greatly in their abilities. They vary in their desires to reach
their potential.” – John Maxwell
“Start strong! Train your brain to shift to work mode by setting a regular time during the day for your lessons.
Set an alarm and stick to your “working hours”
LESSON PREVIEW/REVIEW
Introduction
MAIN LESSON
C++ Output
In C++, cout sends formatted output to standard output devices, such as the screen. We use the cout object along
with the << operator for displaying output.
C++ Input
In C++, cin takes formatted input from standard input devices such as the keyboard. We use the cin object
along with the >> operator for taking input.
Example 3: Integer Input/Output
#include <iostream> using Output:
namespace std; Enter an integer: 70
The number is: 70
int main() {
int num; In the program, we used cin >> num; to take input
cout << "Enter an integer: "; from the user. The input is stored in the
cin >> num; // Taking input variable num. We use the >> operator with cin to
cout << "The number is: " << num; take input.
return 0; }
Note: If we don't include the using namespace std; statement, we need to use std::cin instead of cin.
return 0;
}