Hour Glass shape with letters (help)

I need the program to print out :

The user enters an odd integer (say, N) in the range 1 to 51
(inclusive). The program then prints an hourglass shape comprised
of N rows of uppercase letters.
For example, if the user enters 7, then the following hourglass
comprised of 7 rows is printed:

DCBABCD (0 spaces preceding first letter)
_CBABC_ (1 space preceding first letter)
__BAB__ (2 spaces preceding first letter)
___A___ (3 spaces preceding first letter)
__BAB__ (2 spaces preceding first letter)
_CBABC_ (1 space preceding first letter)
DCBABCD (0 spaces preceding first letter)

This is what I have:


#include <iostream>
using namespace std;
int main ()
{
int N ;
do
{

cout << endl << "Please enter an odd integer, 1 - 51 : " ;
cin >> N ;
if( N < 1 || N > 51 || N % 2 == 0 ) //less than 1 , more than 51 or even
cout << "Invalid number." << endl;
}
while( N < 1 || N > 51 || N % 2 == 0 ); //less than 1, greater than 51 or even

cout << endl ;
int amount_letters = N;
int amount_spaces = 0;
for (int i=0; i < N; ++i) //as many rows as there are letters
{
for (int j=0; j < amount_spaces; ++j) //print spaces
std::cout << ' ';

for (int k=0; k < amount_letters; ++k) //print letters
std::cout << 'A';

amount_letters -= 2; //decrease letters
amount_spaces += 2; //increase spaces

std::cout << std::endl; //print newline
}
}
What was wrong with your existing thread?
http://www.cplusplus.com/forum/beginner/112365/
Topic archived. No new replies allowed.