Pages - Menu

Getting input from users in C++

Getting input from users in C++

Getting input from users is really easy. You only have to write statement and you are done for that.

You might wanna have a look on the hello world example that I wrote before this.

Here is the code to get input from the users (explaination of the code is after the code):

#include <iostream>
using namespace std;
int main(){
    cout << "Type your age: ";
    int a;
    cin >> a;
    cout << "You typed: " << a;
    cout << endl;
    system('PAUSE');
}

int a; just declares variable of integer datatype. cout is used to show messages on the screen and cin is used to take input from the users through console window. I used endl in cout statement, it is to move the cursor to the new line.