Programming Challenge Chapter 3 – Q #22 Word Game – Tony Gaddis – Starting Out With C++
Problem: -
- His or her name
- His or her age
- The name of a city
- The name of a college
- A profession
- A type of animal
- A pet s name
Solution: -
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name, city, college, profession, animal_type, petname;
int age;
cout << "Enter Your Name:
";
getline(cin, name);
cout << "Enter Your Age:
";
cin >> age;
cin.ignore();
cout << "Enter Your City Name:
";
getline(cin, city);
cout << "Enter Your College
Name ";
getline(cin, college);
cout << "Enter Your Profession
Name: ";
getline(cin, profession);
cout << "Enter Your Animale
Type: ";
getline(cin, animal_type);
cout << "Enter Your Pet Name:
";
getline(cin, petname);
cout << endl;
cout << "There once was a
person named " << name << " who lived in " << city << ".";
cout << "At the age of\n" << age << ", " << name << " went to college at
" << college << ". ";
cout << name << " graduate and went
back to work\nas a " << profession << ". " << "Then, " << name << " adobted a(n) ";
cout << animal_type << " named " << petname << ". They\nboth lived happily ever after!";
return 0;
}
This is the solution of this question
OUTPUT OF THIS QUESTION
Explanation of this Solution
- Add a header file for string.
- Declare 6 string variables for input.
- Declare a int variables for input
- Take input one by one
- In last, display output on the screen.
- Return 0 to the main function.
0 Comments