Let's use the cin statement to take user input from the terminal.

Problem Statement

Let's suppose you work in a hospital management system, and you have been given a task to input patient data to keep records for the doctor to review. Your job is to take the following variable values associated with the user:

  1. Patient name

  2. Patient age

  3. Patient contact

Expected output

You need to write a code that prompts the user to enter all of these values, save them as variables, and print their output in a presentable way. You have to identify the datatype of variables and correct formatting for printing the output. The output should look like this:

The patient name is: John Doe
Their age is: 39
Their contact number is: 0298938948

Coding challenge

You can test your code in the following code playground:

Write your input in the following field before running the code. We're taking input like this because of the limitation of the platform.

Press + to interact
#include <iostream>
using namespace std;
int main() {
// your code goes here
return 0;
}

Enter the input below

It is recommended​​ that you try solving the exercise yourself before viewing the solution.

If you’re stuck, click the “Show Solution” button.

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy