need help!

Hello, I'm having some problems writing this program. I'm supposed to display a graph that compares the store's sales. I've almost finished it, but when I go to run the program the stars wouldn't show up.

This is what I've done:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
using namespace std;

int main()
{
	double sales;    //today's sales for five stores
	char star = '*';

	cout << " Enter today's sales for five different stores." << endl;

	for(int count = 1; count <= 5; count++)
	{
		cout << "\n Enter today's sales for store " << count << ":";
		cin >> sales;
	}
	
	cout << "\n SALES BAR GRAPH" << endl;
	cout << " (Each * = $100)" << endl;
	for( int count = 1; count <= 5; count++)
	{
		star = 100;
		star /= sales;
		cout << "Store " << count << ":  " << star << endl;
	}
		
	return 0;
}


The part with the SALES BAR GRAPH is supposed to display like this:
1
2
3
4
5
6
7
SALES BAR CHART
  (Each * = $100)
  Store 1: *************
  Store 2: ***************
  Store 3: ********************
  Store 4: ********
  Store 5: *********************


Please help me out..
What exactly are lines 21-22 supposed to do? star is a char, doing math operations on it is weird and probably not what you want.
sales needs to save the sales for each store. This could be done by changing sales to an array, vector or map of doubles. The number of stars to print should be sales/100 = numStars. To create the output of stars you could use a string with the assign function.

string& assign ( size_t n, char c );

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <string>
using namespace std;

int main()
{
	double sales[5];   // input of 5 elements (stores)
	string star;
	
	cout << " Enter today's sales for five different stores." << endl;
	
	for(int count = 1; count <= 5; count++)
	{
		cout << "\n Enter today's sales for store " << count << ":";
		cin >> sales[count]; // store input for all 5 stores individually
	}
	
	cout << "\n SALES BAR GRAPH" << endl;
	cout << " (Each * = $100)" << endl;

	for( int count = 1; count <= 5; count++)
	{
		star.assign(sales[count] / 100, '*');
		cout << "Store " << count << ": "  << star << endl;
	}
	
	return 0;
}


You can learn more baout this line: star.assign(sales[count] / 100, '*');, by reading:
http://www.cplusplus.com/reference/string/string/assign/


As well the 'sales' is stored in an array. You can learn more about arrays here:
http://www.cplusplus.com/doc/tutorial/arrays/

Time for bed.
Hello, I know I solved this problem already, but I figured that I could also use a nested loop to display the stars in the output.
Yes, you could do this:

1
2
3
4
5
6
7
for(int count = 1; count <= 5; count++)
{
	cout << "Store " << count << ": ";
	for (int stars = 0; stars < sales[count] / 100; stars++)
		cout << "*";
	cout << endl;
}


I wouldn't want code looking that yucky unless I was doing something special with it. :/
Topic archived. No new replies allowed.