fork download
  1. //Charlotte Davies-Kiernan CS1A Chapter 3 P 148 #22
  2. //
  3. /******************************************************************************
  4.  *
  5.  * Display a Word Game
  6.  * ____________________________________________________________________________
  7.  * This program takes what the user enters and displays a story with those
  8.  * words incoporated into it.
  9.  * ___________________________________________________________________________
  10.  * INPUT
  11.  * name // user's choice of name
  12.  * age // user's choice of age
  13.  * cityName // user's choice of city
  14.  * college // user's choice of college
  15.  * profession // user's choice of profession
  16.  * animal // user's choice of type of animal
  17.  * petName // user's choice of pet name
  18.  *
  19.  * OUTPUT
  20.  * shortStory // story using the user's words
  21.  *****************************************************************************/
  22. #include <iostream>
  23. #include <iomanip>
  24. using namespace std;
  25. int main()
  26. {
  27. string name; //INPUT - name user decides to input
  28. int age; //INPUT - age user decides to input
  29. string cityName; //INPUT - city name user decides to input
  30. string college; //INPUT - college user decides to input
  31. string profession; //INPUT - profession user decides to input
  32. string animal; //INPUT - animal type the user decides to input
  33. string petName; //INPUT - pet name the user decides to input
  34. //
  35. // Collect User Input
  36. cout << "Enter a name: ";
  37. getline(cin,name);
  38.  
  39. cout << "Enter the name of a city: ";
  40. getline(cin,cityName);
  41.  
  42. cout << "Enter an age: ";
  43. cin >> age;
  44. cin.ignore();
  45.  
  46. cout << "Enter the name of a college: ";
  47. getline(cin,college);
  48.  
  49. cout << "Enter a profession: ";
  50. getline(cin,profession);
  51.  
  52. cout << "Enter a type of animal: ";
  53. getline(cin,animal);
  54.  
  55. cout << "Enter a pet name: ";
  56. getline(cin,petName);
  57.  
  58. //
  59. // Display the story!
  60. cout << "\n\nHere's your story!: \n";
  61. cout << "There once was a person named " << name << "who lived in ";
  62. cout << cityName << ".\n";
  63. cout << "At the age of " << age << ", " << name;
  64. cout << "went to college at " << college << ".\n";
  65. cout << name << "graduated and went to work as a " << profession << ".\n";
  66. cout << "Then, " << name << "adopted a(n) " << animal << " named ";
  67. cout << petName << ".\n";
  68. cout << "They both lived happily ever after!\n";
  69. return 0;
  70. }
Success #stdin #stdout 0.01s 5324KB
stdin
Charlotte 
 Los Angeles 
30
UCLA
 computer engineer 
 cat  
mittens
stdout
Enter a name: Enter the name of a city: Enter an age: Enter the name of a college: Enter a profession: Enter a type of animal: Enter a pet name: 

Here's your story!: 
There once was a person named Charlotte who lived in  Los Angeles .
At the age of 30, Charlotte went to college at UCLA.
Charlotte graduated and went to work as a  computer engineer .
Then, Charlotte adopted a(n)  cat   named mittens.
They both lived happily ever after!