Advertisement
Guest User

Salary Array

a guest
Oct 8th, 2012
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.46 KB | None | 0 0
  1. // Lab 3
  2. // James Strickland
  3. // 10/2/12
  4. // COP2224
  5. // LAB6 Salary [ARRAY]
  6.  
  7. /*    INSTRUCTIONS:
  8. (Salesperson Salary Ranges) Use a one-dimensional array to solve the following problem. A
  9. company pays its salespeople on a commission basis. The salespeople each receive $200 per week
  10. plus 9 percent of their gross sales for that week. For example, a salesperson who grosses $5000 in
  11. sales in a week receives $200 plus 9 percent of $5000, or a total of $650. Write a program (using an
  12. array of counters) that determines how many of the salespeople earned salaries in each of the following
  13. ranges (assume that each salesperson’s salary is truncated to an integer amount):
  14. a) $200–299
  15. b) $300–399
  16. c) $400–499
  17. d) $500–599
  18. e) $600–699
  19. f) $700–799
  20. g) $800–899
  21. h) $900–999
  22. i) $1000 and over
  23. */
  24.  
  25. #include <iostream>
  26. #include <cmath>
  27.  
  28. using namespace std;
  29.  
  30. int main()
  31. {
  32.     // Initialize array
  33.     int rangeSales[8] = {0};  // 0 to 9
  34.  
  35.     // Declare variables
  36.     int salary = 200;
  37.     int grossSales = 0;
  38.     int commission = 0;
  39.     int flooredNum = 0;
  40.  
  41.     cout << "Enter gross sales:  ";
  42.     cin >> grossSales;
  43.     cout << endl;
  44.     // floor(grossSales);
  45.  
  46.     while(grossSales != -1)
  47.     {
  48.  
  49.         commission = grossSales * .09;
  50.         salary = salary + commission;
  51.  
  52.         if (salary >= 200 && salary <= 300)
  53.         {
  54.             rangeSales[0]++;
  55.         }
  56.         else if (salary >= 300 && salary <= 399)
  57.         {
  58.             rangeSales[1]++;
  59.         }
  60.         else if (salary >= 400 && salary <= 500)
  61.         {
  62.             rangeSales[2]++;
  63.         }
  64.         else if (salary >= 500 && salary <= 600)
  65.         {
  66.             rangeSales[3]++;
  67.         }
  68.         else if (salary >= 600 && salary <= 700)
  69.         {
  70.             rangeSales[4]++;
  71.         }
  72.         else if (salary >= 700 && salary <= 800)
  73.         {
  74.             rangeSales[5]++;
  75.         }
  76.         else if (salary >= 800 && salary <= 900)
  77.         {
  78.             rangeSales[6]++;
  79.         }
  80.         else if (salary >= 900 && salary <= 1000)
  81.         {
  82.             rangeSales[7]++;
  83.         }
  84.         else if (salary >= 1000)
  85.         {
  86.             rangeSales[8]++;
  87.         }
  88.  
  89.     } // end while
  90.  
  91.     cout << "$200-$299 range is: " << rangeSales[0] << endl;
  92.     cout << "$300-$399 range is: " << rangeSales[1] << endl;
  93.     cout << "$400-$499 range is: " << rangeSales[2] << endl;
  94.     cout << "$500-$599 range is: " << rangeSales[3] << endl;
  95.     cout << "$600-$699 range is: " << rangeSales[4] << endl;
  96.     cout << "$700-$799 range is: " << rangeSales[5] << endl;
  97.     cout << "$800-$899 range is: " << rangeSales[6] << endl;
  98.     cout << "$900-$999 range is: " << rangeSales[7] << endl;
  99.     cout << "$1000 and up      : " << rangeSales[8] << endl;
  100.  
  101.  
  102.     system("pause");
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement