fork download
  1. //Mahmoud Saleh CSC5 *Forked* Chapter 5 #17, P297
  2. //
  3. /****************************************************************************************************
  4. *
  5. * Compare Store Sales
  6. *__________________________________________________________________________________
  7. * This program accepts sales data from a number of stores and displays those data
  8. * in the form of a bar graph.
  9. *
  10. *__________________________________________________________________________________
  11. * INPUT
  12. * storeData : The revenue of each store
  13. * Number of stores
  14. * Plot symbol
  15. *
  16. * OUTPUT
  17. * store1 : Amount made by store 1 represented by '*'
  18. * store2 : Amount made by store 2 represented by '*'
  19. * store3 : Amount made by store 3 represented by '*'
  20. * store4 : Amount made by store 4 represented by '*'
  21. * store5 : Amount made by store 5 represented by '*'
  22. * bar graph comparing stores using '*'
  23. * A traditional bar graph representing the sales of each store by store.
  24. *
  25. ****************************************************************************************************/
  26. #include <iostream>
  27. #include <iomanip>
  28. #include <string>
  29.  
  30. using namespace std;
  31.  
  32. int main()
  33. {
  34. //Declaring variables
  35. int count; //Count for 'for loop'
  36. int count2; //Count for while loop to concatanate '*'
  37. int store; //Sales Revenue input by user
  38. int starNum; //Number of stars (points) based on revenue
  39. string storeStar; //Concatanated string of total number of stars
  40. string store1; //Number of stars for store one
  41. string store2; //Number of stars for store two
  42. string store3; //Number of stars for store three
  43. string store4; //Number of stars for store four
  44. string store5; //Number of stars for store five
  45.  
  46.  
  47. //Establishing for loop to run for 5 iterations
  48. for(count = 0; count<5; count++)
  49. {
  50. //Initializing and resetting variables
  51. store = 0;
  52. count2 = 0;
  53. starNum =0;
  54. storeStar = "";
  55.  
  56. //Using while loop to validate input making sure its a positive integer
  57. cout << "Enter today's sales for store " << count + 1 << ":\n";
  58. cin >> store;
  59. while(store<0) //conver this to standard input validation
  60. {
  61. cout << "Invalid Input store " << endl;
  62. cout << "Enter today's sales for store " << count + 1 << ":\n";
  63. cin >> store;
  64. }
  65. //Dividing input value by 100 and assigning it to starNum (number of points)
  66. starNum = store/100;
  67.  
  68. //While loop to assign "*" points to the store based on input
  69. while (count2 < starNum)
  70. {
  71. storeStar += "*";
  72. count2 += 1;
  73. }
  74.  
  75. //Switch statement to assign the total points to the exact store
  76. switch(count+1)
  77. {
  78. case 1:
  79. store1 = storeStar;
  80. break;
  81. case 2:
  82. store2 = storeStar;
  83. break;
  84. case 3:
  85. store3 = storeStar;
  86. break;
  87. case 4:
  88. store4 = storeStar;
  89. break;
  90. case 5:
  91. store5 = storeStar;
  92. break;
  93. }
  94.  
  95.  
  96. }
  97.  
  98. //Displaying comparison bar graph
  99. cout << endl;
  100. cout << "SALES BAR CHART" << endl;
  101. cout << "(Each * = $100)" << endl;
  102. cout << "Store 1: " << store1 << endl;
  103. cout << "Store 2: " << store2 << endl;
  104. cout << "Store 3: " << store3 << endl;
  105. cout << "Store 4: " << store4 << endl;
  106. cout << "Store 5: " << store5 << endl;
  107.  
  108. return 0;
  109. }
Success #stdin #stdout 0.01s 5288KB
stdin
1000
-1200
1200
1800
800
1900
stdout
Enter today's sales for store 1:
Enter today's sales for store 2:
Invalid Input store 
Enter today's sales for store 2:
Enter today's sales for store 3:
Enter today's sales for store 4:
Enter today's sales for store 5:

SALES BAR CHART
(Each * = $100)
Store 1: **********
Store 2: ************
Store 3: ******************
Store 4: ********
Store 5: *******************