fork download
  1. // Cenyao Huang CS1A Chapter 3, P. 148, #22
  2. /*******************************************************************************
  3. * PLAY A WORD GAME
  4. * This program plays a word game with the user.
  5. *
  6. * Input
  7. * name : the user's name
  8. * age : the user's age
  9. * city : the name of a city
  10. * college : the name of a college
  11. * profession : a profession
  12. * animal : a type of animal
  13. * petName : a pet's name
  14. *
  15. * Output
  16. * Display the following story with user's input in appropriate locations:
  17. * There once was a person named [name] who lived in CITY. At the age of
  18. * [age], [name] went to college at [college]. [name] graduated and went to work
  19. * as a [profession]. Then, [name] adopted a(n) [animal] named [petName]. They
  20. * both lived happily ever after!
  21. *
  22. ******************************************************************************/
  23.  
  24.  
  25. #include <iostream>
  26. #include <string>
  27. using namespace std;
  28.  
  29. int main() {
  30. string name, age, city, college, profession, animal, petName; // assign data type to variable
  31.  
  32. cout << "Please provide your name, age, a city, a college, a profession, an animal, and a pet name: " << endl; // get necessary input
  33. cin >> name >> age >> city >> college >> profession >> animal >> petName;
  34. cout << name << " " << age << " " << city << " " << college << " " << profession << " " << animal << " " << petName << endl;
  35.  
  36. cout << endl << "There once was a person named " << name << " who lived in " << city << ". At the age of " << age << ", " <<
  37. name << " went to college at " << college << ". " << name << " graduated and went to work as a " << profession << ". Then, " << name << " adopted a(n) " << animal << " named " << petName << ". They both lived happily ever after!"; // display story
  38.  
  39.  
  40. return 0;
  41. }
Success #stdin #stdout 0.01s 5324KB
stdin
Katie 21 Sacramento MonsterUniversity programmer tiger Stripes
stdout
Please provide your name, age, a city, a college, a profession, an animal, and a pet name: 
Katie 21 Sacramento MonsterUniversity programmer tiger Stripes

There once was a person named Katie who lived in Sacramento. At the age of 21, Katie went to college at MonsterUniversity. Katie graduated and went to work as a programmer. Then, Katie adopted a(n) tiger named Stripes. They both lived happily ever after!