DSA interview question
You're writing the first piece of a check-in tool for a college fest. At the registration desk each attendee types three things: their age, their full name (which may contain spaces), and their height in metres. Your program must read these three values and print one formatted badge line. It sounds trivial, but almost every beginner's first bug lives here: the name comes out empty, or only the first word is read, or the height prints with ten decimal places. Getting input and output exactly right is also what online assessments silently test on every single problem, since your code has to parse the input format itself.
Example: input 21, Riya Sharma, 1.6 (one value per line) should print Name: Riya Sharma, Age: 21, Height: 1.60 m.
void readAndPrintBadge(); // reads age, full name, height from stdin; prints one line to stdout
| Input (one value per line) | Output | Explanation |
|---|---|---|
21 / Riya Sharma / 1.6 | Name: Riya Sharma, Age: 21, Height: 1.60 m | Name has a space, so it must be read as a whole line |
18 / Arjun / 1.8 | Name: Arjun, Age: 18, Height: 1.80 m | Height padded to exactly 2 decimals |
45 / Dr. Meera Iyer / 1.627 | Name: Dr. Meera Iyer, Age: 45, Height: 1.63 m | Three-word name; height rounded to 2 decimals |
0 / A / 0.5 | Name: A, Age: 0, Height: 0.50 m | Smallest valid values |
(Confirm: the name is on its own line and may contain spaces; height should always print with exactly 2 decimal places.)
cin >> and getline.)getline return an empty string right after cin >> age?"endl and '\n'?"On Practick another engineer interviews you live for 60 minutes on a question from this bank. They have the full interviewer guide beside the call: the expected answer to every follow-up, hints to give if you stall, and a scoring rubric. You get the model solution once the session settles. It is free: interview someone for an hour and you have earned your own.
Book a free mock interviewAll 474 dsa interview questions
DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in