2 Replies - 15814 Views - Last Post: 12 March 2008 - 02:39 PM Rate Topic: -----

#1 Amateen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 23-February 08

in c++ how to draw a box

Posted 12 March 2008 - 12:52 PM

hey all, i am stuck at a function thing. i have done most of the code but don't know how to do one part please help.
   # include <iostream> 
using namespace std;
//Function prototype
void draw_line(char what, int length, int height);
int main()

{
	cout << " Mateen Rehman " << endl;
	cout << " please enter a letter" << endl;
	
		
	char what = 'a';
		
	cout  << " please enter a number for length" << endl;
	int length = 15;
	cin >> length;
	cout << " please enter a number for height" << endl;
	int height = 20;
	cin>> height;
	for (length = 0; length < 16; length ++)
		cout << what << endl;
	for (height = 0; height < 21; height ++)
		cout << what << endl;
}
	void draw_line(char what, int length, int height)
{	
		cout << what << endl;   


how do i do this part " Repeatedly call the function draw_line to display a box of the desired length, height and character." how do i do this. thanks

This post has been edited by NickDMax: 12 March 2008 - 04:55 PM


Is This A Good Question/Topic? 0
  • +

Replies To: in c++ how to draw a box

#2 letthecolorsrumble  Icon User is offline

  • Student of The Sun
  • member icon

Reputation: 27
  • View blog
  • Posts: 555
  • Joined: 07-November 07

Re: in c++ how to draw a box

Posted 12 March 2008 - 01:09 PM

Well according to your function definition draw_line, you can simply call that function once an the output will be a box.

You should learn how to use nested for loop for this task, I assume you tried to use nested for loops but incorrectly.

Try this:
#include <iostream>
using namespace std;


//Function prototype
void draw_box(char what, int length, int height);


int main() {
	char what;
	int height, length;

	cout << " Mateen Rehman " << endl;

	cout << " please enter a letter" << endl;
	cin  >> what;
	cout << " please enter a number for length" << endl;
	cin  >> length;
	cout << " please enter a number for height" << endl;
	cin  >> height;

	draw_box(what, length, height);
	
	return 0;
}


void draw_box(char what, int length, int height) {
	//using nested for-loops for output
	for (int i = 0; i < height; i++) {	
		
		for (int j = 0; j < length; j++)
			cout << what;

		cout<<endl;//new line when the characters are printed horizontally once
	}
}





I have changed the draw_line function name to draw_box.

More help? Keep posting ! :)
Was This Post Helpful? 0
  • +
  • -

#3 Amateen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 23-February 08

Re: in c++ how to draw a box

Posted 12 March 2008 - 02:39 PM

thanks a lot that really helped.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1