//Devin Scheu CS1A Chapter 5, P. 297, #17
//
/**************************************************************
*
* DISPLAY SALES BAR CHART
* ____________________________________________________________
* This program determines a bar chart comparing sales for five
* stores based on user input.
*
* Computation is based on a loop converting sales amounts to
* asterisks, with each asterisk representing $100 of sales
* ____________________________________________________________
* INPUT
* storeSales : The sales amount for each of the five stores
*
* OUTPUT
* barChart : The bar chart representation of sales
*
**************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
int main () {
//Variable Declarations
const int NUM_STORES = 5; //OUTPUT - Number of stores
double storeSales[NUM_STORES]; //INPUT - The sales amount for each of the five stores
string barChart; //OUTPUT - The bar chart representation of sales
//Prompt for Input
for (int store = 0; store < NUM_STORES; store++) {
cout << "Enter today's sales for store " << (store + 1) << ": ";
cin >> storeSales[store];
while (storeSales[store] < 0) {
cout << "\nError: Please enter a non-negative number: ";
cin >> storeSales[store];
}
}
//Display Header
cout << "\nSALES BAR CHART" << endl;
cout << "(Each * = $100)" << endl;
//Display Bar Chart
for (int store = 0; store < NUM_STORES; store++) {
int asterisks = static_cast<int>(storeSales[store] / 100);
cout << "Store " << (store + 1) << ": ";
for (int i = 0; i < asterisks; i++) {
cout << "*";
}
cout << endl;
}
return 0;
} //end of main()