fork download
  1. //Matthew Santos CS1A Ch. 3, Pg. 148, #22
  2. /***********************************************
  3.  *
  4.  * PLAY WORD GAME
  5.  * _____________________________________________
  6.  * This program accepts various statements provided by the user
  7.  * and reformats those statements into a descriptive paragraph.
  8.  *
  9.  * Asks for various information and displays
  10.  * a story using that information.
  11.  * _____________________________________________
  12.  * INPUT
  13.  * name : name of user
  14.  * age : age of user
  15.  * city : chosen city
  16.  * college : chosen college
  17.  * profession : chosen profession
  18.  * animal : chosen animal
  19.  * petname : name of pet
  20.  *
  21.  *
  22.  * OUTPUT
  23.  * A descriptive paragraph based on input
  24.  *
  25.  ***********************************************/
  26. #include <iostream>
  27. #include <string>
  28. using namespace std;
  29.  
  30. int main() {
  31.  
  32. //Defines words to get
  33. string name; //name of user
  34. string age;
  35. string city;
  36. string college;
  37. string profession;
  38. string animal;
  39. string petname;
  40.  
  41. //Asks for words
  42. cout << "Please provide the following...\n";
  43. cout << "Name:\n";
  44. cout << "Age:\n";
  45. cout << "City:\n";
  46. cout << "College:\n";
  47. cout << "Profession:\n";
  48. cout << "Animal:\n";
  49. cout << "Name of pet:\n";
  50.  
  51. getline(cin, name);
  52. cin >> age;
  53. cin.ignore();
  54. getline(cin, city);
  55. getline(cin, college);
  56. cin >> profession;
  57. cin >> animal;
  58. cin >> petname;
  59.  
  60. //Outputs full word game
  61. cout << "There once was a person named " << name << " who lived in " << city << ".\n";
  62. cout << "At the age of " << age << ", " << name << " went to college at " << college << ".\n";
  63. cout << name << " graduated and went to work as a " << profession << ".\n";
  64. cout << "Then, " << name << " adopted a(n) " << animal << " named " << petname << ".\n";
  65. cout << "They both lived happily ever after!";
  66.  
  67. return 0;
  68. }
Success #stdin #stdout 0s 5308KB
stdin
Matthew Santos
18
Rancho Santa Margarita
Saddleback College
barista 
cat 
Bob
stdout
Please provide the following...
Name:
Age:
City:
College:
Profession:
Animal:
Name of pet:
There once was a person named Matthew Santos who lived in Rancho Santa Margarita.
At the age of 18, Matthew Santos went to college at Saddleback College.
Matthew Santos graduated and went to work as a barista.
Then, Matthew Santos adopted a(n) cat named Bob.
They both lived happily ever after!