### Sales Bar Chart

I'm doing my homework assignment for beginning C++ Class. I need to 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: ******************

So I'm getting it a little. We have to use loops, no arrays. I have the following as my code. I'm able to input store data and it does display a sales bar chart but like this :
SALES BAR CHART
(Each * = \$100)
Store 1:
Store 2:
Store 3:
Store 4:
Store 5:
******

Any help/advice would be greatly appreciated! I'm new the forums as well. I'm so thankful to have found this. I'm a nurse with NO programming experience, this is a whole new world to me!

 ``1234567891011121314151617181920212223242526272829303132333435`` `````` #include using namespace std; int main() { int store; int profit; char stars ='*'; cout <<"Enter today's sales for five different stores." <> profit; } { cout<<"SALES BAR CHART"<
Did your instructor explicitly say not to use arrays? The thing is, in your first loop, where you ask the user to input the sale data, the profit variable will always be overwritten once the loop restarts, because the user enters new data - effectively making the sales of all stores equal to the final profit entered.
The directions for the assignment say "The program MUST use for loops to display the bar charts."

Hmm, so that's why I'm only getting a the bar chart to display store 5 data in the chart. Can you point me in the direction of writing this loop correctly?
Sure. I would use for loops as well as arrays.

You'll use one integer array with five elements to represent the sales - one for each store.

I've written the first part for you, let's see if you can figure out the rest.
I've tried to keep it simple:

 ``1234567891011`` ``````#include int main() { const int num_stores = 5; int sales[num_stores]; for(int i=0; i> sales[i]; }``````
Last edited on
Topic archived. No new replies allowed.