View difference between Paste ID: aai4rgWx and yTsx1uzr
SHOW: | | - or go back to the newest paste.
1
#include <iostream>
2
#include <string>
3
4
using namespace std;
5
6
string getPyramid(const string&);
7
8
int main() 
9
{
10
	string letters {""};
11
	cout << "Give me some letters: ";
12
	cin >> letters;
13
	cout << getPyramid(letters);
14
}
15
16
string getPyramid(const string &letters)
17
{
18
	string pyramid {""};
19
	
20
	for (int i {0}; i < (int)letters.length(); i++)
21
	{
22
		for (int j {0}; j < (int)letters.length() - 1 - i; j++) pyramid += ' ';	//spaces
23
		for (int j {0}; j <= i; j++) pyramid += letters.at(j);	//begin to center
24
		for (int j {i-1}; j >= 0; j--) pyramid += letters.at(j); //center (exclusive) to begin
25
		pyramid += '\n';	//endline
26
	}
27
	
28
	return pyramid;
29
}