home *** CD-ROM | disk | FTP | other *** search
/ Beginning C++ Through Gam…rogramming (2nd Edition) / BCGP2E.ISO / source / chapter01 / lost_fortune.cpp < prev   
Encoding:
C/C++ Source or Header  |  2003-09-17  |  1.6 KB  |  53 lines

  1. // Lost Fortune
  2. // A personalized adventure
  3.  
  4. #include <iostream>
  5. #include <string>
  6.  
  7. using std::cout;
  8. using std::cin;
  9. using std::endl;
  10. using std::string;
  11.  
  12. int main()
  13. {
  14.     const int GOLD_PIECES = 900;
  15.     int adventurers, killed, survivors;
  16.     string leader;
  17.  
  18.     //get the information
  19.     cout << "Welcome to Lost Fortune\n\n";
  20.     cout << "Please enter the following for your personalized adventure\n";
  21.  
  22.     cout << "Enter a number: "; 
  23.     cin >> adventurers;
  24.  
  25.     cout << "Enter a number, smaller than the first: ";
  26.     cin >> killed;
  27.  
  28.     survivors = adventurers - killed;
  29.  
  30.     cout << "Enter your last name: ";
  31.     cin >> leader;
  32.  
  33.     //tell the story
  34.     cout << "\nA brave group of " << adventurers << " set out on a quest ";
  35.     cout << "-- in search of the lost treasure of the Ancient Dwarves. ";
  36.     cout << "The group was led by that legendary rogue, " << leader << ".\n";
  37.  
  38.     cout << "\nAlong the way, a band of marauding ogres ambushed the party. ";
  39.     cout << "All fought bravely under the command of " << leader;
  40.     cout << ", and the ogres were defeated, but at a cost. ";
  41.     cout << "Of the adventurers, " << killed << " were vanquished, ";
  42.     cout << "leaving just " << survivors << " in the group.\n";
  43.  
  44.     cout << "\nThe party was about to give up all hope. "; 
  45.     cout << "But while laying the deceased to rest, ";
  46.     cout << "they stumbled upon the buried fortune. ";
  47.     cout << "So the adventurers split " << GOLD_PIECES << " gold pieces.";
  48.     cout << leader << " held on to the extra " << (GOLD_PIECES % survivors);
  49.     cout << " pieces to keep things fair of course.\n";
  50.  
  51.     return 0;
  52. }
  53.