fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6. // Individual variables for each store instead of an array
  7. int store1 = 0, store2 = 0, store3 = 0, store4 = 0, store5 = 0;
  8.  
  9. // Single for loop for the sales input
  10. for (int i = 1; i <= 5; i++) {
  11. cout << "Enter today's sales for store " << i << ": ";
  12. if (i == 1) cin >> store1;
  13. else if (i == 2) cin >> store2;
  14. else if (i == 3) cin >> store3;
  15. else if (i == 4) cin >> store4;
  16. else if (i == 5) cin >> store5;
  17. }
  18.  
  19. // Display the bar chart header
  20. cout << "\nSALES BAR CHART\n";
  21. cout << "(Each * = $100)\n";
  22.  
  23. // Display the bar graph for each store
  24. for (int i = 1; i <= 5; i++) {
  25. cout << "Store " << i << ": ";
  26.  
  27. // Retrieve the sales for the current store
  28. int currentSales = 0;
  29. if (i == 1) currentSales = store1;
  30. else if (i == 2) currentSales = store2;
  31. else if (i == 3) currentSales = store3;
  32. else if (i == 4) currentSales = store4;
  33. else if (i == 5) currentSales = store5;
  34.  
  35. // Calculate and display asterisks
  36. int numAsterisks = currentSales / 100;
  37. for (int j = 0; j < numAsterisks; j++) {
  38. cout << "*";
  39. }
  40. cout << endl;
  41. }
  42.  
  43. return 0;
  44. }
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
Enter today's sales for store 1: 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: