Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,302 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,029 people online right now. Registration is fast and FREE... Join Now!




in c++ how to draw a box

 
Reply to this topicStart new topic

in c++ how to draw a box

Amateen
post 12 Mar, 2008 - 11:52 AM
Post #1


New D.I.C Head

*
Joined: 23 Feb, 2008
Posts: 10

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.
CODE
   # 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 Mar, 2008 - 03:55 PM
User is offlineProfile CardPM

Go to the top of the page

letthecolorsrumble
post 12 Mar, 2008 - 12:09 PM
Post #2


Student of The Sun

Group Icon
Joined: 7 Nov, 2007
Posts: 550



Thanked 1 times
My Contributions


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:
cpp

#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 ! smile.gif
User is offlineProfile CardPM

Go to the top of the page

Amateen
post 12 Mar, 2008 - 01:39 PM
Post #3


New D.I.C Head

*
Joined: 23 Feb, 2008
Posts: 10

thanks a lot that really helped.
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/22/08 01:57AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month