fork(1) download
  1. //Mahmoud Saleh CSC5 Chapter 5 #17, P297
  2. //
  3. /****************************************************************************************************
  4. *
  5. * Compare Store Sales
  6. *________________________________________________________________________________
  7. * This Program will compare The sales of 5 different stores
  8. * and display them in a bar graph
  9. * This program accepts sales data from a number of stores and displays those data
  10. * in the form of a bar graph.
  11. *
  12. *_________________________________________________________________________________
  13. * INPUT
  14. * storeData : The revenue of each store
  15. * Number of stores
  16. * Plot symbol
  17. *
  18. * OUTPUT
  19. * store1 : Amount made by store 1 represented by '*'
  20. * store2 : Amount made by store 2 represented by '*'
  21. * store3 : Amount made by store 3 represented by '*'
  22. * store4 : Amount made by store 4 represented by '*'
  23. * store5 : Amount made by store 5 represented by '*'
  24. * bar graph comparing stores using '*'
  25. * A traditional bar graph representing the sales of each store by store.
  26. *
  27. ****************************************************************************************************/
  28. #include <iostream>
  29. #include <iomanip>
  30. #include <string>
  31.  
  32. using namespace std;
  33.  
  34. int main()
  35. {
  36. //Declaring variables
  37. int count;
  38. int count2;
  39. int count3;
  40. int store;
  41. int storeNum;
  42. string storeStar;
  43. string store1;
  44. string store2;
  45. string store3;
  46. string store4;
  47. string store5;
  48.  
  49. //Initializing variable storeNum
  50. storeNum = 1;
  51.  
  52. //Establishing for loop to run for 5 iterations
  53. for(count = 0; count<5; count++)
  54. {
  55. //Initializing and resetting variables
  56. count3 = 0;
  57. store = 0;
  58. count2 = 0;
  59. storeStar = "";
  60.  
  61. //Using while loop to validate input making sure its a positive integer
  62. while(count3<1)
  63. {
  64. cout << "Enter today's sales for store " << count + 1 << ":\n";
  65. cin >> store;
  66. //If statement if input value is negative
  67. if (store < 0)
  68. cout << "Invalid Input try again.\n";
  69. else
  70. count3 += 1;
  71. }
  72. //Dividing input value by 100 and reassigning it for comparison
  73. store /= 100;
  74.  
  75. //While loop to assign "*" points to the store based on input
  76. while (count2 < store)
  77. {
  78. storeStar += "*";
  79. count2 += 1;
  80. }
  81.  
  82. //Switch statement to assign the total points to the exact store
  83. switch(storeNum)
  84. {
  85. case 1:
  86. store1 = storeStar;
  87. break;
  88. case 2:
  89. store2 = storeStar;
  90. break;
  91. case 3:
  92. store3 = storeStar;
  93. break;
  94. case 4:
  95. store4 = storeStar;
  96. break;
  97. case 5:
  98. store5 = storeStar;
  99. break;
  100. }
  101.  
  102. //Statement to ensure next input is given to the next store
  103. storeNum += 1;
  104. }
  105.  
  106. //Displaying comparison bar graph
  107. cout << endl;
  108. cout << "SALES BAR CHART" << endl;
  109. cout << "(Each * = $100)" << endl;
  110. cout << "Store 1: " << store1 << endl;
  111. cout << "Store 2: " << store2 << endl;
  112. cout << "Store 3: " << store3 << endl;
  113. cout << "Store 4: " << store4 << endl;
  114. cout << "Store 5: " << store5 << endl;
  115.  
  116. return 0;
  117. }
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 try again.
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: *******************