Google News
logo
C++ Program to Print Number Entered by User
In the following example of C++ program that prompts the user to enter a number and then prints that number to the console :
Program :
#include <iostream>

int main() {
    int num;
    std::cout << "Enter a number: ";
    std::cin >> num;
    std::cout << "You entered: " << num;
    return 0;
}
Output :
Enter a number: 5
You entered: 5
* This program declares a variable num of type int. The program then prompts the user to enter a number using the std::cout and std::cin objects from the iostream library.

* The >> operator is used to input the user's number into the num variable. Finally, the program uses std::cout to output a message that displays the user's number to the console.