ok i almost have this solution but i need help

Write a program that asks the user for 2 numbers: the width and the height. The program prints a box of asterisks of that width and height.

For example, if the user types in 5 and 3, the program outputs
*****
*****
*****
..........................
I cant figure out how to get it to print the boxes instead of the numbers. this is what i have.

#include <iostream>
using namespace std;
int main ()
{
int n;
int i;
cout<<"Give me a number"<<endl;
cin>>n;
cout<<"Give me another number"<<endl;
cin>>i;
while(n*i){
cout<<n*i<<endl;
system("pause");
return 0;
}
}
It's printing a number becuase n*i is an expression.

You need to create a pair of nested for loops. The outter one for rows and the inner one for columns. Inside the inner loop, you will want to print one asterisk for each column. You will also want to print an endl after each row.

PLEASE USE CODE TAGS (the <> formatting button) when posting code. It makes your code easier to read and it also makes it easier to respond to you post.

Last edited on
This code might help you..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include<iostream>
using namespace std;
int main()
{
int a,b;
int i,j;
cout<<"Enter two numbers\n";
cin>>a>>b;
for(i=0;i<a;i++)
 {
  for(j=0;j<b;j++)
  {
   cout<<"\t"<<"*";
  }
  cout<<"\n";
 }
}
Topic archived. No new replies allowed.