C++ for Beginners: C++ Program to Print Number Entered by User

Hits: 17

(C++ programming Example for Beginners)

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 user to enter a number.

When user enters an integer, it is stored in variable number using cin.

Then it is displayed in the screen using cout.

 

C++ for Beginners: C++ Program to Print Number Entered by User

Sign up to get end-to-end “Learn By Coding” example.



Disclaimer: The information and code presented within this recipe/tutorial is only for educational and coaching purposes for beginners and developers. Anyone can practice and apply the recipe/tutorial presented here, but the reader is taking full responsibility for his/her actions. The author (content curator) of this recipe (code / program) has made every effort to ensure the accuracy of the information was correct at time of publication. The author (content curator) does not assume and hereby disclaims any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from accident, negligence, or any other cause. The information presented here could also be found in public knowledge domains.