fork download
  1. //Xinnuo Wang CS1A chapter 3 , P.148, #22
  2. //
  3. /*******************************************************************************
  4. *
  5. * Play A World Game
  6. *-------------------------------------------------------------------------------
  7. * This program asks the personal information and display a story.
  8. *-------------------------------------------------------------------------------
  9. * INPUT
  10. * name : The user's name need to be input
  11. * age : The user's age need to be input
  12. * city : The city's name need to be input
  13. * college : The college's name need to be input
  14. * profession : The user's profession need to be input
  15. * animal : A type of animal
  16. * petName : The pet's name
  17. * OUTPUT
  18. *
  19. *******************************************************************************/
  20. #include <iostream>
  21. #include <string>
  22. using namespace std;
  23.  
  24. int main()
  25. {
  26. string name; //INPUT - The user's name
  27. int age; //INPUT - The user's age
  28. string city; //INPUT - The city's name
  29. string colledge; //INPUT - The college's name
  30. string profession;//INPUT - The user's profession
  31. string animal; //INPUT - A type of animal
  32. string petName; //INPUT - The pet's name
  33. //
  34. //Input Data
  35. cout << "Enter the name" <<endl;
  36. cin>> name ;
  37. cout << "Enter the age " <<endl;
  38. cin>> age;
  39. cout << "Enter the name of the city" <<endl;
  40. cin>> city;
  41. cout << "Enter the college" <<endl;
  42. cin>> colledge;
  43. cout << "Enter the profession" <<endl;
  44. cin.ignore();
  45. getline(cin,profession);
  46. cout << "Enter the type of animal" <<endl;
  47. cin>> animal;
  48. cout << "Enter the pet's name" <<endl;
  49. cin>> petName;
  50. //
  51. //Output Result
  52. cout <<"There once was a person named "<< name<<" who lived in "<<city<<"."<<" At the age of "<< age<<", " <<name<<" went to college at "<<colledge<<". "<< name<<" graduated and went to work as a "<<profession<<"." <<" Then, "<<name <<" adopted a(n) "<<animal<<" named "<<petName<<". They both lived happily ever after!"<< endl;
  53.  
  54. return 0;
  55. }
Success #stdin #stdout 0s 5312KB
stdin
Winnie
25
California
UCLA
computer engineer
dog
Mua

stdout
Enter the name
Enter the age 
Enter the name of the city
Enter the college
Enter the profession
Enter the type of animal
Enter the pet's name
There once was a person named Winnie who lived in California. At the age of 25, Winnie went to college at UCLA. Winnie graduated and went to work as a computer engineer. Then, Winnie adopted a(n) dog named Mua. They both lived happily ever after!