Let's use the cin statement to take user input from the terminal.
We'll cover the following
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:
Patient name
Patient age
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 DoeTheir age is: 39Their 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.
#include <iostream>using namespace std;int main() {// your code goes herereturn 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