fork download
  1. //Kevin Thomas CS1A Chapter 3, P. 148, #22
  2. /**************************************************************
  3. *
  4. * Play Word Game
  5. * ____________________________________________________________
  6. * This program will collect data from the user and use it to play a word game.
  7. * ____________________________________________________________
  8. * INPUT
  9. * name: Represents the user's name
  10. * age: Represents the user's age
  11. * city: Represents a city name entered by the user
  12. * college: Represents a college name entered by the user
  13. * job: Represents a profession entered by the user
  14. * animal: Represents a type of animal entered by the user
  15. * petName: Represents the name of a pet entered by the user
  16. * story:
  17. * OUTPUT
  18. * The story made by combining the user's information with the story provided by the problem.
  19. *
  20. **************************************************************/
  21. #include <iostream>
  22. using namespace std;
  23.  
  24. int main() {
  25. //Declare variables
  26. string name;
  27. string age;
  28. string city;
  29. string college;
  30. string job;
  31. string animal;
  32. string petName;
  33. string response;
  34.  
  35. //Ask the user for each piece of information, then store it in the respective variable.
  36. cout << "Enter your name: " << endl;
  37. cin >> name;
  38. cout << "Enter your age: " << endl;
  39. cin >> age;
  40. cout << "Enter a city name: " << endl;
  41. cin >> city;
  42. cout << "Did you go to college? (Y/N)" << endl;
  43. cin >> response;
  44. if (response == "Y") {
  45. cout << "Enter a college name: " << endl;
  46. cin >> college;
  47. }
  48. cout << "Enter a job title: " << endl;
  49. cin >> job;
  50. cout << "Enter a type of animal: " << endl;
  51. cin >> animal;
  52. cout << "Enter a pet name: " << endl;
  53. cin >> petName;
  54.  
  55. //Output the resulting paragraph
  56. if (response == "Y"){
  57. cout << "There once was a person named " << name << " who lived in " << city << ". At the age of " << endl;
  58. cout << age << " , " << name << " went to college at " << college << ". " << name << " graduated and went to work" << endl;
  59. cout << "as a " << job << ". Then, " << name << " adopted an " << animal << " named " << petName << ". They" << endl;
  60. cout << "both lived hapily ever after!";
  61. }
  62. else
  63. {
  64. cout << "There once was a person named " << name << " who lived in " << city << ". At the age of " << endl;
  65. cout << age << " , " << name << ". " << name << " graduated and went to work" << endl;
  66. cout << "as a " << job << ". Then, " << name << " adopted an " << animal << " named " << petName << ". They" << endl;
  67. cout << "both lived hapily ever after!";
  68. }
  69.  
  70.  
  71. return 0;
  72. }
Success #stdin #stdout 0.01s 5404KB
stdin
Kevin
18
Irvine
N
Student
dog
Kevin Jr. 
stdout
Enter your name: 
Enter your age: 
Enter a city name: 
Did you go to college? (Y/N)
Enter a job title: 
Enter a type of animal: 
Enter a pet name: 
There once was a person named Kevin who lived in Irvine. At the age of 
18 , Kevin. Kevin graduated and went to work
as a Student. Then, Kevin adopted an dog named Kevin. They
both lived hapily ever after!