Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

get user input c++

#include <iostream>

using namespace std;

int main()
{
    string first_name, last_name;
    int age;

    //prompt the user to enter there first name and store the value
    cout << "Enter your first name: ";
    getline(cin, first_name);

    //request the user to enter there last name and store the value
    cout << "Enter your last name: ";
    getline(cin, last_name);

    //request the user to enter there age and store the value
    cout << "Enter your age: ";
    cin >> age;

    //print an output string to the terminal
    cout << "Your full name is " << first_name << " " << last_name << " and you are " << age << " years old." << endl;
}
 
PREVIOUS NEXT
Tagged: #user #input
ADD COMMENT
Topic
Name
9+6 =