In this post, we will learn how to print an integer entered by the user using C++ Programming language.
This program asks the user to enter an integer, then it prints the entered number on the screen.
So, without further ado, let’s begin this tutorial.
C++ Program to Print Number Entered by the User
// C++ Program to Print Number Entered by the User #include <iostream> using namespace std; int main(){ int num; // Asking for input cout << "Enter an integer: "; cin >> num; // Displaying output cout << "The entered number is: " << num; return 0; }
Output
Enter an integer: 72
The entered number is: 72
How Does This Program Work ?
int num;
In this program, we have declared an int data type variable named num.
// Asking for input cout << "Enter an integer: "; cin >> num;
Then, the user is asked to enter an integer. The input is taken with the help of cin statement.
// Displaying output cout << "The entered number is: " << num;
Finally, the entered number is displayed on the screen using the cout statement.
Conclusion
I hope after going through this post, you understand how to print number entered by the user using C++ Programming language.
If you have any doubt regarding the program, feel free to contact us in the comment section. We will be delighted to guide you.
Also Read: