Trying to write a prgram that prints out stacks of astericks

Hello, I recently posted asking for help on my program, thank you it helped a lot! I am almost finished, but I am having a problem with the output, and I need to do something rather major to it that I have no idea how to do.

I know my code is written rather illogically, and inefficiently, but I just broke my leg, and the painkillers are really not helping me think straight, I just want to finish this stupid thing.

So the program's purpose is to take an input of integers separated by spaces (3 2 2 4 5 2 etc.) and convert it into vertical lines of asterisks, so if i put in a 1 2 3 2 1, it would return a stack of one, a stack of two, a stack of three, a stack of 2 and a stack of one asterisks. So they are in like a pyramid shape. My program does this, but the first element and the last element are missing an asterisk. That's the problem I'm trying to resolve.

The other thing I need help with is that I'm trying to make it so that any amount of integers can be entered in and it will work. Right now I have it programmed for 5, because I do not know how to initialize an array without a size. I also don't know how to call the size (thought it was Array.size but that didn't seem to work.) Thanks for your help!

CODE:

#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main()
{
	int max;
//put numbers into array	
     int Array[5];
     for(int i=0; i<Array.size; ++i)
         std::cin>>Array[i];
//make another array in descending order
	int temp;
	int Sorted[5];
	for (int i=0; i < 5; i++){
		Sorted[i] = Array[i];
	}
        for(int i = 0; i <5; i++)
        {
                for(int j = 0;j < 5 - 1; j++)
                {
                        if(Sorted[j] < Sorted[j+1])
                        {
                                //we need to swap
                                temp = Sorted[j+1];
                                 Sorted[j+1]=Sorted[j];
                                Sorted[j] = temp;
                        }
                }
        }     

     //printing astericks
     for (int row = 0; row < max+1; ++ row){
	  max = Sorted[row];
		for (int y=0; y< 5; ++y){
			if (Array[y] < max){
				cout << " ";
			} else {
				cout << "*";
			}
			//cout << "*" << endl;
		}
		cout << "" <<  endl;
	}
}

To initialize an "array" without a size, I recommend... a vector.
http://cplusplus.com/reference/stl/vector/

In regards to your actual problem, I'm running extremely low on caffeine so at the moment I cannot tell you exactly how to fix your problem the proper way with minimum effort on your part, although if consistently the first and last elements are missing an asterisk then... maybe an if statement that will print an extra asterisk in those two cases? Probably someone else will be able to give further details on how to fix your problem, or me in a few hours.

-Albatross
Topic archived. No new replies allowed.