fork download
  1. // Elaine Torrez Chapter 4 P. 222, #11
  2. /**************************************************************************
  3.  * BOOK CLUB POINTS
  4.  * ------------------------------------------------------------------------
  5.  * This program asks the user to enter the number of books purchased this
  6.  * month. It then uses an if/else if structure to determine the number of
  7.  * points awarded based on the following chart:
  8.  *
  9.  * 0 books -> 0 points
  10.  * 1 book -> 5 points
  11.  * 2 books -> 15 points
  12.  * 3 books -> 30 points
  13.  * 4+ books -> 60 points
  14.  * ------------------------------------------------------------------------
  15.  * INPUT
  16.  * books : The number of books purchased
  17.  *
  18.  * OUTPUT
  19.  * The number of points awarded
  20.  **************************************************************************/
  21.  
  22. #include <iostream>
  23. using namespace std;
  24.  
  25. int main()
  26. {
  27. int books; // Number of books purchased
  28. int points; // Points awarded
  29.  
  30. // Get input
  31. cout << "Enter the number of books purchased this month: ";
  32. cin >> books;
  33.  
  34. // Determine points
  35. if (books == 0)
  36. points = 0;
  37. else if (books == 1)
  38. points = 5;
  39. else if (books == 2)
  40. points = 15;
  41. else if (books == 3)
  42. points = 30;
  43. else if (books >= 4)
  44. points = 60;
  45.  
  46. // Display output
  47. cout << "You earned " << points << " points.\n";
  48.  
  49. return 0;
  50. }
  51.  
Success #stdin #stdout 0.01s 5304KB
stdin
2
stdout
Enter the number of books purchased this month: You earned 15 points.