Hi, i'm willing to print a pyramid but it's not working quite good my programme is followings:
Anyone please help me..:) NOTE:"REMEMBER, you can't use extra things in this programme except bool variables and if, if else statements as they are prohibited and that's the MAIN task"

#include<iostream>
using namespace std;
int main()
{
int size,half,mode,left,right;
cout<<"Please, enter the size of the base of the pyramid ";
cin>>size;
mode=size%2;
 if(mode=1)
 {
    half=(size-1)/2;
    left=half;
    right=half;
    for(int line=1;line<=(size-half);line++)
    {
        while(left<half && left>0)
        {
            cout<<"L";
            left--;
        }
        for(int stars=1;stars<=(line+(line-1));stars++)
        {
          cout<<"*";
        }
        while(right<half && right>0)
        {
            cout<<"R";
            right--;
        }
        cout<<endl;
        left=half--;
        right=half-1;
        if(left<0 && right<0)
        {
            break;
        }
    }
 }
 else
 {
     cout<<"Please enter odd positive integer to get complete and desired pyramid\n";
 }
 return 0;
}
#include <iostream>
#include <cassert>

using namespace std;


void Repeat      (const char symbol, const int amount);
int  RowToWidth  (const int row);
int  ObtainHeight();


int ObtainHeight()
{
    int height(0);

    do
    {
        if (cin.fail())
        {
            cerr << "Invalid input.\n";

            cin.clear();
            while (cin.get() != '\n');
        }

        cout << "Enter the height of the pyramid: ";
        cin  >> height;
    }
    while (cin.fail());

    assert(height >= 0);

    return height;
}


void Repeat (const char symbol, const int amount)
{
    assert(amount >= 0);

    for (int i = 0; i < amount; i++)
    {
        cout << symbol;
    }
}


int RowToWidth (const int row)
{
    assert(row >= 1);
    return(row * 2 - 1);
}


int main()
{
    int height = ObtainHeight();
    int width  = height * 2 - 1;

    for (int row = 1; row <= height; row++)
    {
        Repeat(' ', (width - RowToWidth(row)) / 2);
        Repeat('*', RowToWidth(row));
        cout << endl;
    }

    return 0;
}
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.