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;
}
}
|