SALES BAR CHART C++

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!
Last edited on
Replace
1
2
3
4
5
6
for (int sales = sales <= 5; sales++); // This for loop is incorrect. a ';' also ends a statement
{
stars = sales/100;
cout << "Store" << store << ":" << "*";
cout << endl;
}
to something like this..

1
2
3
4
5
6
7
8
stars = sales/100;
cout << "Store" << store << ":"
for(int y=0;y<stars;y++)
{
  cout << "*";
}
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");
This is what I have and I'm close but it still separates the bar after each store. I need it to look like this:

Store 1: ******
Store 2: ********
Store 3: ***********

I have no idea what I'm doing wrong.

#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
int sales = 0;
int store = 0;
int stars;

for (int store = 1; store <= 5; store++)
{
cout << "Enter today's sale for store " << store << ":";
cin >> sales;

cout << "SALES BAR CHART:" << endl;
cout << "(Each * = $100)" << endl;

stars = sales/100;
cout << "Store" << store << ":";

for (int y = 0; y < stars; y++)
{
cout << "*";
}
cout << endl;
}

system("PAUSE");
return EXIT_SUCCESS;}
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.
1
2
for(int x=0;x<5;x++)
cin >> store[x];
Then use the loop again to do the stars
Topic archived. No new replies allowed.