### Displaying Pyramid

Guys I am having trouble coding this one :( Any help please?

Input
You are to ask the user to input from the console(keyboard) two data, M and N. M is an integer (M>0)that tells us the size of the pyramid and N is the character symbol you will use to draw the replica of the pyramid.

Sample Run
 ```Input a number and a symbol: 4 * * * * * * * * * * * * * * * * * * * * * * *```

Here is my partial code. But the problem is when the size of the pyramid is more than 10 there's a bug -_-
 ``123456789101112131415161718192021222324252627282930313233343536373839`` ``````#include using namespace std; main() { int a, i, j, h; char symbol; cout << "Enter the size of the pyramid: "; cin >> a; cout << "Enter the symbol to be used: "; cin >> symbol; cout << endl; for(i = 1;i <= a;i++){ //1 for (j = a;j >= i;j--){ cout << " ";} for(h = 1;h <= i-1;h++){ cout << symbol << " ";} //2 for (j = a;j >= i;j--){ cout << " ";} for(h = 1;h <= i;h++){ cout << symbol << " ";} //3 for (j = a;j >= i;j--){ cout <<" ";} for(h = 1;h <= i-1;h++){ cout << symbol << " ";} cout << endl;} system("pause"); }``````
Last edited on
i dont think anyone would spend time to make a code example for this but if you come up with one which might have errors or algorithmic mistake or uncompleted. people would like to help you
Last edited on
Like Ceset said, write some code, then ask for help. But just to get you started: it uses loops ;P
Here :)) sorry :)

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162`` ``````#include #include using namespace std; int main(){ int i,space,rows,k=0; char inp; string tria; cout << "number and a symbol: "; cin >> rows >> inp; /* cout << "Enter a character: "; cin >> inp;*/ for(i=1;i
actually your code is quite fine just add `#include <windows.h> `.to use system("pause"); u need to add it. then everything is good to go. if i didnt miss something.
Last edited on
Heres the new one much better but when the rows is more than 10 the pyramids overlap each other.

 ``123456789101112131415161718192021222324252627282930313233343536373839`` ``````#include using namespace std; main() { int a, i, j, h; char symbol; cout << "Enter the size of the pyramid: "; cin >> a; cout << "Enter the symbol to be used: "; cin >> symbol; cout << endl; for(i = 1;i <= a;i++){ //1st for (j = a;j >= i;j--){ cout << " ";} for(h = 1;h <= i-1;h++){ cout << symbol << " ";} //2nd for (j = a;j >= i;j--){ cout << " ";} for(h = 1;h <= i;h++){ cout << symbol << " ";} //3rd for (j = a;j >= i;j--){ cout <<" ";} for(h = 1;h <= i-1;h++){ cout << symbol << " ";} cout << endl;} system("pause"); }``````
Is pause even needed?

Never mind, though you were running from the cmd line
Last edited on
I'm using Dev C++
well cant say for sure but the reason might be consoles width limit.

i suppose you are working on deitel&deitel c++ book. ignore if i m wrong. yeah it gives you great examples and homework to work on so you can learn it better. but dont spend so much time on one thing. pass to another if you understand the usage of loop
This is one of our take home exams eh? :(
 ``123456`` ``````void pause() { cin.ignore(256, '\n'); cout << "Press ENTER to continue"; cin.get(); }``````
well so funny same question over and over hah :D :D these deitel dudes
Last edited on
Topic archived. No new replies allowed.