goldwinbryanr wrote: |
---|
I don't know what/where to start |
I'm confused. Didn't you write the code you have posted?
First of all remove all the junk includes at the start. The only one you need is
#include <iostream>
and maybe
#include <string>
Then please get rid of the unneeded
1 2
|
std::cin.get();
_pause();
|
so that we can run it in c++ shell.
goldwinbryanr wrote: |
---|
1) need first to know the height that the user will enter |
But surely you have already done this with
1 2 3
|
int n;
cout << "Enter height of the triangle:";
cin >> n;
|
goldwinbryanr wrote: |
---|
2) declare a variable that will store arrays |
But surely you have tried to do this with
char x[n] {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'};
Note that this is illegal in standard C++. Both modern C and modern Fortran allow you declare the array size at run time, but it is a VLA (variable-length array) and not legitimate in C++. It also wouldn't match the length of the initialiser list unless n was 10, so both C and Fortran would baulk at it. Given your specification this could simply be written
char x[10] {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'};
goldwinbryanr wrote: |
---|
3) i do not know what's next |
That's not consistent with the code that you have given. Where did it come from?
for(int y=0; y <= n; y++){
This would give n+1 rows. You need n, so
for(int y=0; y < n; y++){
The next loop gives n-y spaces. It's OK, but takes your variable count to 5. You could actually achieve the same with
cout << string( n-y, ' ' );
so reducing the number of variables.
The next loop is supposed to write the character x[y] the number y+1 times. So fix:
- the loop index (you can't re-use x; you need another variable name)
- the number of times the loop runs;
- the array element being output here.
Then it works.
You will learn more if you write your own code. This appears to have been taken, with minor modification, from somewhere else.