Here is the corresponding C++ code. Use your text editor to create
the source program. Call the file
Copy the following lines.
xterm window, compile it with the command
g++ whoyou.cc -o whoyou
If the compilation fails, the error message specifies the line number
where the error occurred. Check over and fix the code.
It is a good idea to become familiar with compiler error messages,
since they don't always pinpoint the error precisely. So after your
compilation succeeds, try deliberately to make the compilation fail.
See how the compiler complains if you omit one of the semicolons (a
common mistake). See how it complains if you misspell the variable
name in one place (another common mistake) or if you leave out
one of the declarations (another common mistake).
When the compilation is successful, run your program with the command
You should be prompted for your name and age. Enter them by
typing your name as a single word without spaces followed by
your age as a single integer and hit the Enter key.
Experiment with various inputs. Try entering your name on one line and age on a second line. Or do a double ``Enter'' between the data items.
Input items translated by the
cin class are "words".
Words are separated by "white space" (spaces, tabs or ends-of-line).
So if you enter your first name and last name with a space between,
the first name will be read as your name and the last name will be
read as your age, probably not what you wanted.