Utilizing arrays create vertical asterisk graph

I am so close, but I could use a little help ...

This program needs to display a vertical graph of asterisks
showing production for each plant in the company ...

Here is what I have so far:

***********************************
This program will read data and
display a vertical graph showing
productivity for each plant.
Reference Display 7.8 pg. 401-3
***********************************
*/
#include <iostream>
#include <cmath>
#include <iomanip>
//#include <conio.h>

using namespace std;

const int NUMBER_OF_PLANTS = 4;

void inputData(int a[], int last_plant_number);
//Precondition: last_plant_number is the declared size of the arraya.
//Postcondition: For plant_number = 1 through last_plant_number:
//a[plant_number-1] equals the total production for plant_number.

void scale(int a[], int size);
//Precondition: a[0] through a[size-1] each has a non-negative value.
//Postcondition: a[i] has been changed to the number of 1000s(rounded to
//an integer) that were originally in a[i], for all i such that 0 <= i <= size -1.

void graph(const int asterisk_count[], int last_plant_number);
//Precondition: asterisk_count[0] throughasterisk_count[last_plant_number-1]
//have nonnegative values.
//Postcondition: A bar graph has been displayed saying thatplant
//number N has produced asterisk_count[N-1] 1000s of units, foreach N such that
//1 <= N <= last_plant_number

void getTotal(int& sum);
//Reads nonnegative integers from the keyboard and
//places their total in sum.

int round(double number);
//Precondition: number >= 0.
//Returns number rounded to the nearest integer.

int main( )
{
int production[NUMBER_OF_PLANTS];
int sum = 0;

cout << "This program displays a graph showing\n"
<<"production for each plant in the company.\n";

inputData(production, NUMBER_OF_PLANTS);
scale(production, NUMBER_OF_PLANTS);
graph(production, NUMBER_OF_PLANTS);

system("pause");
return 0;
}

void inputData(int a[], int last_plant_number)
{
for (int plant_number = 1;
plant_number <= last_plant_number; plant_number++)
{
cout << endl
<< "Enter production data for plant number "
<< plant_number << endl;
getTotal(a[plant_number- 1]);
cout << plant_number-1 << "" << a[plant_number-1] << endl;
}
}

void get_total(int& sum)
{
cout << "Enter number of units produced by each department.\n"
<< "Append a negative number to the end of the list.\n";

//sum = 0;
int next;
cin >> next;
while (next >= 0)
{
sum = sum + next;
cin >> next;
}

cout << "Total = " << sum << endl;
}

void scale(int a[], int size)
{
for (int index = 0; index < size; index++)
a[index] = round(a[index] / 1000.0);
}


//Uses cmath:

int round(double number)
{
return static_cast<int>(floor(number +0.5));
}

void graph(const int a[], int n)
{
char graph[20][20];
int i, j, max = a[0];
//MAX calculates the highest productivity and stores it in largest varialbe

for(i = 1; i < n; i++)
{
if(a[i] > max)
max = a[i];
}
//Arranges the n asterisk in a two dimensional array
for(i = 0; i < max; i++)
{
int count = 0;
for(j = max - 1; j >= 0; j--)
{
if(count - a[i])
graph[j][i] = ' ';
else graph[j][i] = '\0';
count++;
}
}
//Asterisks will be displayed in a graph vertically
for(i = 0; i < n; i++)
{
for(j = 0; j < max; j++)
{
cout << graph[i][j] << "\t";
}
cout << "\n";
}

cout << "\nUnits produced in thousands of units:\n";
for(i = 0; i < max; i++)

// for(i = max-1; i >= 0; i--)
// {cout << setw(3) << i << " ";
// for(j = 0; j < n; j++)
// cout << graph[i][j] << " ";
// cout << endl;
// }
// for(i = 0; i < n; i++)
// {
// if(i == 0)
//cout << " ";
//cout << " plant ";
// }
// cout << endl;
//
// for(i = 0; i < n; i++)
// {
// if(i == 0)
//cout << " ";
//cout<<" "<< i + 1 << " ";
// }
cout << endl;
}
I should add that there are 4 manufacturing plants and it should be for any given week, and data should be read in separately for each dept.
Each * represents 1000 units of output.
Topic archived. No new replies allowed.