I am having trouble creating an inverted half-square out asterisks. The problem requires three nested for-loops, I believe, but am unsure as how to proceed. Here is the work I have so far, with the UN-inverted half-square code in italics. The inverted portion should be a simple manipulation of that code, I would think.

#include <iostream.h>
int main()
{
    using namespace std;

    
    int height, SIZE, runNum;
    string figType;
    
        //  Allows all three figures to be created in one run, if so desired.
        cout<< "How many times do you want to run this program?\t\t";
        cin>> runNum;
        for(int j=0; j<runNum; j++)
        {
            //  Decides which figure will be created, a square (S),
            //  half-square (H), or rectangle (B)
            cout<< "\n\n\nEnter figure type (S, H, B)\t\t\t\t";
            cin>> figType;

    
            //  Creates the square figure out of asterisks (S)
            if(figType == "S")
            {
                cout<< "Enter width of figure\t\t\t\t\t";
                cin>> SIZE;
                for(int cols = 1; cols <= SIZE; cols ++)
                {
                    cout<< "*";
                    for(int rows = 1; rows <= (SIZE-1); rows ++)
                    {
                        cout<< "*";
                    }
                    cout<< "\n";
                }        
            }
    
    
           [I] //  Creates the half-square figure (H)
            if(figType == "H")
            {
                cout<< "Enter width of figure\t\t\t\t\t";
                cin>> SIZE;
                for(int cols = 1; cols <= SIZE; cols ++)
                {
                    for(int rows = 1; rows <= cols; rows ++)
                    {
                        cout<< "*";
                    }
                    cout<< "\n";
                }        
            }[/I]
    
    
    
            //  Creates the rectangle figure out of asterisks (B)
            if(figType == "B")
            {
                cout<< "Enter width of figure\t\t\t\t\t";
                cin>> SIZE;
                cout<< "Enter height of figure\t\t\t\t\t";
                cin>> height;
                for(int cols = 1; cols <= height; cols ++)
                {
                    cout<< "*";
                    //  Determines width of rectangle
                    for(int rows = 1; rows <= (SIZE-1); rows ++)
                    {
                        cout<< "*";
                    }    
                    cout<< "\n";
                }        
            }
    }
cout<< "\n\nCaleb Cordes\nHexadecimal\nAsterisks";    

return 0;
    
}

I am having trouble creating an inverted half-square out asterisks. The problem requires three nested for-loops, I believe, but am unsure as how to proceed. Here is the work I have so far, with the UN-inverted half-square code in italics. The inverted portion should be a simple manipulation of that code, I would think.

What does an inverted half square look like? If I have a square of side length 6, it's this (it looks a little distorted since distance between new lines is longer than distance between characters):

******
******
******
******
******
******

If I cut it in half horizontally, it's no longer a square, but a 6 x 3 rectangle:

******
******
******

If I cut in half vertically it's a different 6 x 3 rectangle

***
***
***
***
***
***

I'm not sure where the "inverted" part comes in. Are we talking about half diamonds?

*
   ***
  *****
 *******
*********

or

*********
 *******
  *****
   ***
    *

I actually solved problem...But for anyone who has trouble with this sort of program, I was trying to make a half-square in the form of a right triangle, as such:

*****
****
***
**
*

a sample of the code is below:

//  Creates the inverted half-square figure (L)
if(figType == "L")
{
     cout<< "Enter width of figure\t\t\t\t\t";
     cin>> SIZE;
     for(int rows = SIZE; rows >= 1; rows--)
     {
          for(int cols = 1; cols <= rows; cols++)
          {
               cout<< "*";
          }
          cout<< "\n";
     }				
}
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.