Popular Tutorials
Start Learning C++Certification Courses
Created with over a decade of experience and thousands of feedback.
Python online compiler
JavaScript online compiler
SQL online compiler
Java online compiler
HTML online compiler
C online compiler
C++ online compiler
C# online compiler
PHP online compiler
Swift online compiler
Kotlin online compiler
TypeScript online compiler
Go online compiler
Rust online compiler
Scala online compiler
Dart online compiler
R online compiler
Ruby online compiler
C++ Program to Print Number Entered by User
In this example, you'll learn to print the number entered by a user using C++ cout statement.
Example: Print Number Entered by User
#include <iostream>
using namespace std;
int main() {
int number;
cout << "Enter an integer: ";
cin >> number;
cout << "You entered " << number;
return 0;
}
Output
Enter an integer: 23 You entered 23
This program asks the user to enter a number.
When the user enters an integer, it is stored in variable number using comment.
Then it is displayed on the screen using cout.
Starting from this example, we will be using the std namespace using the code:
using namespace std;
This will allow us to write cout, cin, endl, etc. instead of std::cout, std::cin, std::endl respectively.
This is simply to make our code cleaner and more readable.
However, using the std namespace is considered a bad practice and we highly recommend you drop this practice once you've mastered the basics of C++.
Did you find this article helpful?