Write a program that asks the user to enter today's sales for five stores. The program should then display a bar graph comparing each store's sales. Create each bar in the bar graph by displaying a row of asterisks. Each asterisk should represent $100 of sales.
Example:
Enter today's sales for store 1: 1000
Enter today's sales for store 2: 1200
Enter today's sales for store 3: 1800
Enter today's sales for store 4: 800
Enter today's sales for store 5: 1900
SALES BAR CHART
(Each * = $100)
Store 1: *********
Store 2: ************
Store 3: *****************
Store 4: ********
Store 5: ******************
I am having a tough time figuring this one out. I think I'm putting too much thought into it or something. I don't know. The professor wants us to use For Loops and While Loops.
Here is what I have:
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int sales;
int stars;
int store;
for (int store = 1; store <= 5; store++)
{
cout << "Enter today's sale for store " << store << ":";
cin >> sales;
}
cout << "Sales Bar Chart\n";
cout << "(Each * = $100)\n";
cout << "Stores" << store << ":";
for (int store = 1; store <=5; store++)
{
for (int counter = 1; counter <= 5; counter++)
{
stars = sales/100;
cout << "Store " << store << ":" << "*";
cout << endl;
}
}
system("PAUSE");
return EXIT_SUCCESS;
}
I am having trouble getting the SALES BAR CHART to display. PLEASE HELP ME!
for (int sales = sales <= 5; sales++); // This for loop is incorrect. a ';' also ends a statement
{
stars = sales/100;
cout << "Store" << store << ":" << "*";
cout << endl;
}
Also, you need to remove the left curly bracket after cin >> sales;, otherwise you'll only get one line of stars and that would be for store #5, and put it just before system("pause");
Then you would need an array, to hold the 5 stores sales figures first. Create an array, let's call int store[5]; Then use the a loop to read in each sales.