this program is supposed to create a box with a horizontal line of the limit that a user inputs from 2-9... for example a limit of 5 would create:
5$$$$
$5$$$
$$5$$
$$$5$
$$$$5
an input of 4 would create:

4$$$
$4$$
$$4$
$$$4

and so on... i cant seem to combine the parts together.... im pretty sure i need 3 for statements, one for the bottom $ part, one for the number and one for the upper $ part. this is what i have so far... they're 2 different files as i dont have a clue how to combine them

int main()
{
    int limit = 5;
    
    for (int row = 1; row < limit; row++)
    {
        for (int col = 0; col < row; col++)
        cout << "$";
        
        cout << endl;
    }    
    system("pause");
    return 0;
}

creates:
$
$$
$$$
$$$$

#include <iostream>
using namespace std;

int main()
{
    int limit = 5;
    
    for (int row = limit; row > 1; row--)
    {
        for (int jam = 1; jam < row; jam++)
        cout << "$";
        cout << endl;
    }
    system("pause");
    return 0;
}

creates:
$$$$
$$$
$$
$

help plz :( i need to figure out how to combine them and put the limit as a horizontal line running through them.

Recommended Answers

All 5 Replies

oh i tried to combine them like this:

#include <iostream>
using namespace std;

int main()
{
    int limit = 5;
    
    for (int row = 1; row < limit; row++)
    {
        for (int col = 0; col < row; col++)
        cout << "$";
        for (int jam = limit; jam > 0; jam--)
        cout << "*";
        cout << endl;
    }    
        
        
    system("pause");
    return 0;
}

but i keep getting
$*****
$$*****
$$$*****
$$$$*****

Easy greasy:

#include <iomanip>
#include <iostream>

using std::cout; using std::cin;
using std::setw; using std::endl;

int main()
{
  int limit;

  cout<<"Limit: ";
  if ( cin>> limit ) {
    cout.fill ( '$' );
    for ( int i = 1; i <= limit; i++ )
      cout<< setw ( i ) << limit << setw ( limit - i ) <<""<<endl;
  }
}

jeez why cant i see these things... you saved my life :)

END TRANSMISSION~

this program is supposed to create a box with a horizontal line of the limit that a user inputs from 2-9... for example a limit of 5 would create:

5$$$$
$5$$$
$$5$$
$$$5$
$$$$5

an input of 4 would create:

4$$$
$4$$
$$4$
$$$4






#include<iostream.h>
#include<conio.h>


int main()
{
    clrscr();
    int input = 5 ;

    for(int i = 0;i<input;i++)
     {
       for(int j=0;j<5;j++)
       {
        if(i==j)
            cout << input;
        else
            cout << "$";
       }


       cout << endl;
    }
     getch();
    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.