fork download
  1. // Nathanael Schwartz CS1A Chapter 4, pg. 221, #11
  2. //
  3. /*******************************************************************************
  4.  *
  5.  * DETERMINE POINTS EARNED
  6.  * _____________________________________________________________________________
  7.  * This program determines the number of points a customer earns based on the
  8.  * number of books purchased in a month.
  9.  *
  10.  * The points are awarded as follows:
  11.  * - 0 books = 0 points
  12.  * - 1 book = 5 points
  13.  * - 2 books = 15 points
  14.  * - 3 books = 30 points
  15.  * - 4+ books = 60 points
  16.  * _____________________________________________________________________________
  17.  * INPUT
  18.  * booksPurchased : Number of books purchased this month
  19.  *
  20.  * OUTPUT
  21.  * pointsEarned : Number of points earned based on books purchased
  22.  *
  23.  ******************************************************************************/
  24. #include <iostream>
  25. using namespace std;
  26.  
  27. int main() {
  28. // Declare variables
  29. int booksPurchased; // INPUT - Number of books purchased
  30. int pointsEarned; // OUTPUT - Points earned
  31.  
  32. // Ask for input
  33. cout << "Enter the number of books purchased this month: \n";
  34. cin >> booksPurchased;
  35.  
  36. // Determine points earned
  37. if (booksPurchased == 0)
  38. pointsEarned = 0;
  39. else if (booksPurchased == 1)
  40. pointsEarned = 5;
  41. else if (booksPurchased == 2)
  42. pointsEarned = 15;
  43. else if (booksPurchased == 3)
  44. pointsEarned = 30;
  45. else if (booksPurchased >= 4)
  46. pointsEarned = 60;
  47. else
  48. cout << "Invalid number of books entered." << endl;
  49.  
  50. // Output the points earned
  51. cout << "You have earned " << pointsEarned << " points." << endl;
  52.  
  53. return 0;
  54. }
  55.  
Success #stdin #stdout 0s 5292KB
stdin
17
stdout
Enter the number of books purchased this month: 
You have earned 60 points.