Try this:
Code:
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
const int MAX=20;
ifstream fin;
string company; // name of company file
char graph[MAX][70]; // columns of blocks
float stock[MAX]; // stock price value
float max=0;
float scale; // scale of columns
float space;
int count;
int i,j; // increments
char block=219;
//get filename
cout << "Enter the name of the company file: ";
cin >> company;
//open file
fin.open(company.c_str());
//error checking
if (!fin)
{
cout << "File does not exist.";
return 0;
}
//read stock value into 1D array
for (count=0; (fin >> stock[count]) && count<MAX; count++)
{
}
max=stock[0];
for (i=1; i<count; i++)
if (stock[i]>max)
max=stock[i];
scale=20/max;
space=80/count;
//array[row][col]
for (i=0; i < count; i++)
for (j=0; j<70; j++)
graph[i][j] = ' ';
//give each array value
for (i=0; i < count; i++)
{
for (j=0; j< stock[i]*scale; j++)
{
graph[i][j]=block;
}
}
cout << endl;
for (j=69; j>=0; j--)
{
for (i=0; i < count; i++)
cout << setw(space) << graph[i][j];
cout << endl;
}
return 0;
}
If you want to print horizontally instead, substitute this for the print:
Code:
cout << endl;
for (i=0; i < count; i++)
{
for (j=0; j<70; j++)
cout << graph[i][j];
cout << endl;
}