fork download
  1. // Castulo Jason Quintero CSC5 Chapter 4, pg. 222, #11
  2. //
  3. /*******************************************************************************
  4.  *
  5.  * Collect and Compute Book Reward Points
  6.  * _____________________________________________________________________________
  7.  * This program collects the user inputs for the number of books
  8.  * purchased each month and rewards points accordingly.
  9.  * _____________________________________________________________________________
  10.  * INPUT
  11.  * books : number of books purchased
  12.  *
  13.  * OUTPUT
  14.  * ZERO_BOOKS : 0 books = 0 points
  15.  * ONE_BOOK : 1 book = 5 points
  16.  * TWO_BOOKS : 2 books = 15 points
  17.  * THREE_BOOKS : 3 books = 30 points
  18.  * FOUR_BOOKS : 4 or more books = 60 points
  19.  *
  20.  ******************************************************************************/
  21. #include <iostream>
  22. using namespace std;
  23. int main() {
  24.  
  25. // CONSTANTS - Points assigned to number of books
  26. const int ZERO_BOOKS = 0;
  27. const int ONE_BOOK = 5;
  28. const int TWO_BOOKS = 15;
  29. const int THREE_BOOKS = 30;
  30. const int FOUR_BOOKS = 60;
  31. int books;
  32. // prompt user
  33. cout << "Book Club Points";
  34. cout << "\nEnter the number of books you have purchased "
  35. "this month: ";
  36. cin >> books;
  37. // determine points
  38. if (books == 0)
  39. cout << "\nYou earned " << ZERO_BOOKS << " points.";
  40. else if (books == 1)
  41. cout << "\nYou earned " << ONE_BOOK << " points.";
  42. else if (books == 2)
  43. cout << "\nYou earned " << TWO_BOOKS << " points.";
  44. else if (books == 3)
  45. cout << "\nYou earned " << THREE_BOOKS << " points.";
  46. else if (books >= 4)
  47. cout << "\nYou earned " << FOUR_BOOKS << " points.";
  48. else
  49. cout << "\nYou entered an invalid number.";
  50. return 0;
  51. }
Success #stdin #stdout 0.01s 5280KB
stdin
4
stdout
Book Club Points
Enter the number of books you have purchased this month: 
You earned 60 points.