using function to create retangle

I'm trying to create a program that print a square (width by length size) with any character the user choose. I'm able to do it with a for loop, but is it possible to do it using function? the code with // is my attemp to do the same thing with function but it doesn't work. Can anyone please help me with this

thank a bunch

#include <iostream>

using namespace std;

//int shape (char,int, int);

int length,width;
char char1;

int main()
{
cout <<"Enter any single character ";
cin >>char1;
cout <<"Enter the Lenght ";
cin >>length;
cout <<"Enter the Width ";
cin >>width;
for (int i=1;i<=length;++i)
{
for (int j=1;j<=width;++j)
{
cout <<char1;

}
cout<<endl;
}


//cout <<shape(char1,length,width);

return 0;

}

//int shape (char a, int b, int c)

//{
// char x;
// int y,z;
// for (int i=1;i<=y;++i)
// {
// for (int j=1;j<=z;++j)
// return x;
// cout<<endl;
// }

//}
You should use a void function for that, naming properly the arguments would help you
1
2
3
4
void shape( char character, int width, int height )
{
    //Your Loop
}


Then just call shape(/*Arguments*/); , without cout
Last edited on
thanks for the hint, that help alot
Topic archived. No new replies allowed.