Need help to do an algorithm

Posts 1–7 of 7 · Page 1 of 1
Need help to do an algorithm
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.
Quote Originally Posted by Xeg View Post
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.
What does this have to do with C++ coding?
Well, it as to be done in C++

:\
Is this in vC++, or can it be regular C++?
Can be in regular c++

but i usually use bloodshed dev-c++

#include <iostream>
using namespace std;

int main()
{
// your code goes here
return 0;
}#include <iostream>
using namespace std;

int main()
{
// trying to find out the code :x
return 0;
}



Need to declare a few variables, need to create input/output statements..i.e.cout<< and cin>> and need to read up on loops.

Can't get this done :\
There basicly the same thing, Its like C#.net and VB.net

And...If your using the same .cpp\.h file, you only need to declare "Using namespace std" at the top once, unless you change it.
Already find out, the code is:

Code:
#include <iostream>
#include <math.h>

using namespace std;
int main()
{
    char letra;
    int h, novaletra;
    cout <<"Por favor, introduza uma letra: ";
    cin >> letra;
    cout <<"\n";
    if((letra>='a' && letra<='z')||(letra>='A' && letra<='Z')){                       
        if(letra>='a' && letra<='z'){letra=letra-'a'+'A';}
        
        char l = letra;
        int altura = letra -'A'+1; 
        for( int i=1; i<= altura; i++){
           for(int j=i; j<altura; j++)
           { cout<<" "; }
           
            for( int j=1; j<=i*2-1; j++)
            { 
                 int media= round((i*2-1)/2);
                 if (media+1>=j){
                    novaletra = l-j+1;
                    cout<<(char)novaletra;
                    h=j;
                 }
                 else{
                    h--;  
                    novaletra = l-h+1;
                    cout<<(char)novaletra;
                         
                 } 
            }
            cout<<"\n";
        }
            
    }system ("PAUSE");
    return 0;
}
Posts 1–7 of 7 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us