So I need help to do a work for school which consists of doing an algorithm that allows you to draw a pyramid of letters. The algorithm should ask the user to input one letter and then drew the pyramid.

Example: If the letter that the user input is 'd' or 'D', the result should be the following:

D
DCD
DCBCD
DCBABCD


or

If the letter that the user input is 'f' or 'F', the result should be the following:

F
FEF
FEDEF
FEDCDEF
FEDCBCDEF
FEDCBABCDEF

____

If some one can do this please post the code, I'd be trully grateful.

Recommended Answers

All 9 Replies

>>If some one can do this please post the code, I'd be trully grateful.
I'm sure you would be grateful, but doing yourself disservice by not doing it yourself. We will NOT do your homework for you. Post the code that you can do and ask questions about what you can not do.

I'm a newbie at C++ I really can't do much, that's why im asking for help.

#include

that's pretty much what I can do lol...
I've missed my classes and tried to read some tutorials but it's too damn confusing, I can't get this going.

if you guys can give me some hints or something like that it would be nice, if not thanks for reading anyways.

>>I've missed my classes and tried to read some tutorials but it's too damn confusing
Well, how about reading your textbook for the class you are taking ?

>>but it's too damn confusing
Yes I agree it is confusing at start. I felt that way too when I first started. Hang in there and keep reading because it will come to you eventually.


Here is the beginning

#include <iostream>
using namespace std;

int main()
{
   // your code goes here
   return 0;
}

Interesting...well, a few things:
You'll need the headers and main function as AD pointed out.
2. You need to declare a few variables.
3. You need to create input/output statements..i.e.cout<< and cin>>;
4. You need to read up on loops.

ya I know, but I really don't know where to start... can someone flash some light?

We have already given you some hints. Now start studying your textbook from page 1 and don't skip ahead. You have to do some studying on your own.

ya I know, but I really don't know where to start... can someone flash some light?

Get a torch and flash your own light...you got to do your work, what happens when you have your final exam/tests...are you going to post those questions here?

I'm a newbie at C++ I really can't do much, that's why im asking for help.

#include

that's pretty much what I can do lol...
I've missed my classes and tried to read some tutorials but it's too damn confusing, I can't get this going.

if you guys can give me some hints or something like that it would be nice, if not thanks for reading anyways.

This is probably the shortest piece of C++ code ever written by someone :)

Well, after some work I got this:

#include <iostream>
using namespace std;
int main()
{
    char letra;
    cout <<"Introduza uma letra\n";
    cin >> letra;
    if((letra>='a' && letra<='z')||
       (letra>='A' && letra<='Z')){                       
        if(letra>='a' && letra<='z'){letra=letra-'a'+'A';}
        int altura = letra -'A'+1; 
       for( int i=1; i<= altura; i++){
           for(int j=i; j<altura; j++) 
            cout<<" ";
            for( int j=1,l = letra; j<=i*2-1; j++)
            cout<<(char)l;
            
            
            
            cout<<"\n";
            }
            
    }system ("PAUSE");
    return 0;
}

I done the pyramid but the problem now is when I enter the letter 'D' instanted of appering

D
DCD
DCBCD
DCBABCD

it shows

D
DDD
DDDDD
DDDDDDD


Can anyone help me to finish the algorithm?

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.