You will need to have the following line in your C++ program:
include <string>so that you can declare a string variable which will store the dog's name somewhere in your main function, something like this:
string dogname = "";
What is your name? Fido How old are you? 6 Hello Fido. You are 42 years old in people years. |
For an extra challenge, you can add some ANSI escape sequences to use colors in your output statements.
Some ANSI ESCAPE SEQUENCES: ESC code sequence Function ----------------- --------------------------- ESC[#;#H or ESC[#;#f Move cusor to line #, column # ESC[#A Move cursor up # lines ESC[#B Move cursor down # lines ESC[#C Move cursor forward # spaces ESC[#D Move cursor back # spaces ESC[#;#R Report current cursor line & column ESC[2J Clear screen and home cursor ESC[K Clear to end of line EOL ESC[#;#;....;#m Set display attributes where # is 00 for normal display (or just 0) 01 for bold on (or just 1) 02 faint (or just 2) 03 standout (or just 3) 04 underline (or just 4) 05 blink on (or just 5) 07 reverse video on (or just 7) 08 nondisplayed (invisible) (or just 8) 22 normal 23 no-standout 24 no-underline 25 no-blink 27 no-reverse 30 black foreground 31 red foreground 32 green foreground 33 yellow foreground 34 blue foreground 35 magenta foreground 36 cyan foreground 37 white foreground 39 default foreground 40 black background 41 red background 42 green background 43 yellow background 44 blue background 45 magenta background 46 cyan background 47 white background ESC [65;81p The A key becomes the Q key ESC [97;113p The a key becomes q ESC [81;65p The Q key becomes A ESC [113;97p The q key becomes a E.g. Reassign the F10 key to ls command. ESC [0;68;"ls";13p The 0;68 is the extended ASCII code for the F10 key and 13 is the ASCII code for a carriage return. Other function key codes F1=59,F2=60,F3=61,F4=62,F5=63 F6=64,F7=65,F8=66,F9=67,F10=68
Here is an example C++ program which
// Program Name: trouble.cpp // Description: Have fun with someone who runs programs blindly // Author: Rocket J. Squirrel // Date: September 11, 1752 #include <iostream> #include <string> using namespace std; //make a constant variable for escape const char ESC = 27; int main(void) { //wreak your havoc string message = "Christmas"; //clear screen cout << ESC << "[2J"; cout << ESC << "[35;1;42m" << message << endl; return 0; }