1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
// input a letter
// output a pyramid with letters according to that letter
// build the pyramid based on the letter
#include <iostream>
#include <cstdlib>
#include <cctype>
using namespace std;
const string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main()
{
enum letterType {A=0,B=1,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z}userLetter;
int spaceCount, spaceLimit, innerloop,loopcount;
char inputLetter;
cin >> inputLetter;
userLetter = (letterType)toupper(inputLetter); // supposed to take user input and convert to constant value
spaceCount = 1;
spaceLimit = int(userLetter); // supposed to assign int from enum where a=0, b=1
loopcount = 1;
do
{
while(spaceCount <= spaceLimit) // insert spaces
{
cout << " ";
spaceCount++;
}
spaceLimit--;
spaceCount = 1;
innerloop = 1;
while(innerloop <= loopcount) // first half of the pyramid
{
cout << char(alphabet[innerloop-1]);
innerloop++;
}
while(innerloop <= 1) // second half of the pyramid
{
cout << char(alphabet[innerloop-1]);
innerloop--;
}
cout << endl;
loopcount++;
}while(loopcount <= int(userLetter)); // supposed to assign int from enum where a=0, b=1, but is getting assigned ASCII value
system("pause");
return 0;
}
|