fork download
  1. //Eesha Tangirala #CS1A Chapter 3, pg. 148, #22
  2.  
  3. //*****************************************************************************
  4.  
  5. //Narrate User's Story
  6.  
  7. //_____________________________________________________________________________
  8. //This program takes the user's name, city, age, college, profession, animal,
  9. //and pet's name to compute a story about them.
  10. //_____________________________________________________________________________
  11.  
  12. //INPUT
  13. //Name
  14. //City
  15. //Age
  16. //College
  17. //Profession
  18. //Animal
  19. //Pet's Name
  20.  
  21. //OUTPUT
  22. //There once was a person named [name] who lived in [city]. At the age of
  23. //[age], [name] went to college at [college]. [name] graduated and went to
  24. //work as a [profession]. Then, [name] adopted a(n) [animal] names [petname].
  25. //They both lived happily ever after!
  26.  
  27. //*****************************************************************************
  28.  
  29. #include <iostream>
  30. #include <iomanip>
  31. using namespace std;
  32.  
  33. int main () {
  34.  
  35. //Data Dictionary: All of the input that will be
  36. //collected from the user.
  37. string name;
  38. string city;
  39. int age;
  40. string college;
  41. string profession;
  42. string animal;
  43. string petname;
  44.  
  45. //Prompt the user for name, city, age, college, profession, pet, and petname.
  46. cout << "What's your name?" << endl;
  47. getline (cin, name);
  48. cout << "Where did you live?" << endl;
  49. getline (cin, city);
  50. cout << "How old were you when you started college?" << endl;
  51. cin >> age;
  52. cin.ignore();
  53.  
  54. cout << "What college did you go to?" << endl;
  55. getline (cin, college);
  56. cout << "What profession did you go into?" << endl;
  57. getline (cin, profession);
  58. cout << "What animal did you adopt?" << endl;
  59. getline (cin, animal);
  60. cout << "What was the name of your pet?" << endl;
  61. getline (cin, petname);
  62.  
  63. //Display the data as a short story.
  64. cout << "There once was a person named " << name <<
  65. " who lived in " << city << "." << endl;
  66. cout << "At the age of " << age << ", " << name <<
  67. " went to college at " << college << "." << endl;
  68. cout << name << " graduated and went to work as a " << profession <<
  69. "." << endl;
  70. cout << "Then, " << name << " adopted a(n) " << animal << " named " <<
  71. petname << "." << endl;
  72. cout << "They both lived happily ever after!" << endl;
  73.  
  74. return 0;
  75. }
Success #stdin #stdout 0s 5316KB
stdin
Jelly Offer Uio
Miami Banks
16
Stanford Uni
Gamer Pro
Blue Penguin
Goofy Smar
stdout
What's your name?
Where did you live?
How old were you when you started college?
What college did you go to?
What profession did you go into?
What animal did you adopt?
What was the name of your pet?
There once was a person named Jelly Offer Uio who lived in Miami Banks.
At the age of 16, Jelly Offer Uio went to college at Stanford Uni.
Jelly Offer Uio graduated and went to work as a Gamer Pro.
Then, Jelly Offer Uio adopted a(n) Blue Penguin named Goofy Smar.
They both lived happily ever after!