fork download
  1. //Diego Martinez CSC5 Chapter 3, P. 148,#22
  2. /*******************************************************************************
  3. * Playing a word game
  4. * ______________________________________________________________________________
  5. * This program plays a game with any user who answers the prompts on the screen.
  6. *
  7. *
  8. *
  9. * Computation is based on the Formula:
  10. * No formula
  11. *
  12. *_______________________________________________________________________________
  13. * INPUT
  14. * User Inputs
  15. *
  16. * OUTPUT
  17. * Name :
  18. * Age :
  19. * City :
  20. * College :
  21. * Profession :
  22. * Animal :
  23. * Pet name:
  24. *******************************************************************************/
  25. #include <iostream>
  26. #include <string>
  27. using namespace std;
  28.  
  29. int main() {
  30. string name, city, college, profession, animal, petName;
  31. int age;
  32.  
  33. // Ask the user for inputs
  34. cout << "Enter your name: ";
  35. getline(cin, name);
  36.  
  37. cout << "Enter your age: ";
  38. cin >> age;
  39. cin.ignore(); // clear leftover newline
  40.  
  41. cout << "Enter the name of a city: ";
  42. getline(cin, city);
  43.  
  44. cout << "Enter the name of a college: ";
  45. getline(cin, college);
  46.  
  47. cout << "Enter a profession: ";
  48. getline(cin, profession);
  49.  
  50. cout << "Enter a type of animal: ";
  51. getline(cin, animal);
  52.  
  53. cout << "Enter your pet's name: ";
  54. getline(cin, petName);
  55.  
  56. // Display the story
  57. cout << "\n\nHere is your story:\n\n";
  58. cout << "There once was a person named " << name << " who lived in " << city << ". ";
  59. cout << "At the age of " << age << ", " << name << " went to college at " << college << ". ";
  60. cout << name << " graduated and went to work as a " << profession << ". ";
  61. cout << "Then, " << name << " adopted a(n) " << animal << " named " << petName << ". ";
  62. cout << "They both lived happily ever after!" << endl;
  63.  
  64. return 0;
  65. }
Success #stdin #stdout 0.01s 5320KB
stdin
Diego
stdout
Enter your name: Enter your age: Enter the name of a city: Enter the name of a college: Enter a profession: Enter a type of animal: Enter your pet's name: 

Here is your story:

There once was a person named Diego who lived in . At the age of -188800243, Diego went to college at . Diego graduated and went to work as a . Then, Diego adopted a(n)  named . They both lived happily ever after!