fork(2) download
  1. /*
  2.  * madlibs.cpp This program prompts the user to type words
  3.  * that are filled in to a short story, like the game MadLibs.
  4.  */
  5.  
  6. #include <iostream>
  7. #include <iomanip>
  8.  
  9. using std::cout;
  10. using std::cin;
  11. using std::string;
  12. using std::endl;
  13. using std::setprecision;
  14.  
  15. int main()
  16. {
  17. string part1 = "Jack and Jill went up the";
  18. string noun1;
  19. string part2 = "to fetch a pail of";
  20. string noun2;
  21.  
  22. string part3 = "Jack fell down and";
  23. string verb1;
  24. string part4 = "his";
  25. string noun3;
  26.  
  27. string part5 = "and Jill came";
  28. string verb2;
  29. string part6 = "after.";
  30.  
  31. string part7 = "Jack should really be more";
  32. string adjective1;
  33. string part8 = "!";
  34.  
  35. string part9 = "His insurance premiums jumped from $";
  36. double number1;
  37. string part10 = "to $";
  38. string part11 = ".";
  39.  
  40. string part12 = "And really, Jill should be more";
  41. string part13 = "too.";
  42.  
  43. string part14 = "Hill climbing can be very";
  44. string adjective2;
  45. string part15 = "! :-)";
  46.  
  47. /* TODO: prompt the user to enter values for noun1, noun2, noun3, verb1, verb2, adjetive1, adjetive2, and number
  48.   * use cin to actually get the input from the user and store the results in the respective variables.
  49.   */
  50. cout << "Enter a noun:\n";
  51. cin >> noun1;
  52. cout << "Enter another noun:\n";
  53. cin >> noun2;
  54. cout << "Enter another noun:\n";
  55. cin >> noun3;
  56. cout << "Enter a verb:\n";
  57. cin >> verb1;
  58. cout << "Enter another verb:\n";
  59. cin >> verb2;
  60. cout << "Enter an adjective:\n";
  61. cin >> adjective1;
  62. cout << "Enter another adjective:\n";
  63. cin >> adjective2;
  64. cout << "Enter a number:\n";
  65. cin >> number1;
  66.  
  67.  
  68. cout << part1 << " " << noun1 << " " << part2 << " " << noun2 << '.' << endl;
  69.  
  70. /* TODO: the rest of these lines don't space the output correctly,
  71.   * and words are running together. Fix this.
  72.   */
  73.  
  74. cout << part3 << verb1 << part4 << noun3 ;
  75.  
  76. cout << part5 << verb2 << part6;
  77.  
  78. cout << part7 << adjective1 << part8 ;
  79.  
  80. //TODO number1 actually represents a dollar amount.
  81. //Use the iomanip library to force cout to print two decimal points
  82. cout << part9 << number1 << part10 << number1*2 << part11 ;
  83.  
  84. cout<< part12<< adjective1 << part13 ;
  85.  
  86. cout<< part14 << adjective2 << part15 ;
  87.  
  88. return 0;
  89. }
Success #stdin #stdout 0s 2992KB
stdin
noun1
noun2
noun3
verb1
verb2
adjective1
adjective2
52.5
stdout
Enter a noun:
Enter another noun:
Enter another noun:
Enter a verb:
Enter another verb:
Enter an adjective:
Enter another adjective:
Enter a number:
Jack and Jill went up the noun1 to fetch a pail of noun2.
Jack fell down andverb1hisnoun3and Jill cameverb2after.Jack should really be moreadjective1!His insurance premiums jumped from $52.5to $105.And really, Jill should be moreadjective1too.Hill climbing can be veryadjective2! :-)