Because of the way that we read and write (line-by-line) that's the way the console output is generated, making it easy to print lines of asterisks.
Below, gives the same result as your code, but using a std::string to create the row of asterisks.
1 2 3 4
|
for (int i = 0; i < AMAX; i++)
{
cout << setw(2) << i << ": " << string(myarray[i], '*') << '\n';
}
|
To do something similar, but displaying vertical lines of asterisks instead of horizontal strings, takes a little bit more effort.
The first thing to do is to determine how many lines of output will be needed. That is (unless applying a scaling factor) find the maximum value stored in the array myarray.
Then you could use a 2D character array with height = the max just found, and the width = AMAX. Fill it with spaces. Place asterisks in vertical columns of the array according to the values found in myarray. Finally, print the entire array, line by line.
But you don't really need a 2D array to do this. Instead, just loop for the number of rows required (max value from the array). Then inside that loop, have another loop, which will print either a space or an asterisk depending on the value found in myarray for that column.
I don't think I'm explaining things very well. See if that makes any sense.