Member Avatar for Techboy1523

Write a program that will prompt the user to input the following: length and width of a rectangle , a character, and a choice for either filled or unfilled.

If the choice is filled, print out a filled rectangle with the indicated length and width using the input character. If the choice is unfilled, print out an unfilled rectangle using the input character.

for example:

Length = 10 character ‘+’
Width = 6 unfilled
+ +
+ +
+ +
+ +
Well it's not posting this rectangle above me right, but there is supposed to be a blank space between the plus signs on the left and right.
Length = 8 character ‘Y’
Width = 3 filled

here's my source code so far. I got it to enter the length width, and character. But getting it to make a rectangle is a whole another story. And how should I prompt it for fill or unfilled, should I declare them? And how do i get it to fill, you don't have to give me the answer just somehow point me in the right direction. Thank you for any help.

#include <iostream>
#include <iomanip>

using namespace std;

int main ()
double length, width;
char sign;

cout << "This program will create a rectangle made up of characters chosen by the user" << endl;
cout << "=============================================================================";
cout << endl << endl;

cout << "Please enter the length of the rectangle";
cin >> length;
cout << endl;

cout << "Please enther the width of the rectangle";
cin >> width;
cout << endl;

cout << "Please enter a character of your choice";
cin >> sign;
cout << endl;

cout << "You enter the length of:\n\n" << length << endl << endl;
cout << "You entered the width of :\n\n" << width << endl << endl;


So besides user input, you've actually made no attempt whatsoever?

Member Avatar for Techboy1523

So besides user input, you've actually made no attempt whatsoever?

Like I said I don't know how to make it into a rectangle. You don't have to give me the answer I would just like to be pointed in the right direction.

Characters along the top.
One character, a bunch of spaces, one character.
Characters along the bottom.

Member Avatar for Techboy1523

Did I piss you off or something by asking for help. I'm sorry I'm not a genius with this stuff like some of you people here. I don't want the answer, I want to learn it myself, and trust me I'm trying to. But I'm having trouble with this and I would just like some help. Is that really too much to ask?

I just need to find the lowest common denominator. These days I never know how deep I need to dig.

I would imagine if you knew how to print a space and a character that I might see some of that in your code. The absense thus generates the question.

If the top and bottom rows have all characters and no spaces and are 10 'spots' in length, my guess for this is that you would loop -- printing 10 characters.

The middle is tougher. It starts with a character, which is then followed by 10 - 2 = 8 characters, and then ends with a character. Now, the top and the bottom aren't like this, so you've got 6 - 2 of these rows.

Besides a few loops, and output of a space or some character, it's 2nd grade math. I don't consider this to be genius-level material.

Member Avatar for Techboy1523

I don't just have to make a rectangle with open space and one with filled space, that would be easy. I have to prompt the computer to fill in the open space or leave it open, I'm stuck there.

So you have an input that says in some way A or B: if A, print a space; if B, print a character. The edges remain the same, no?

Consider that the difference between filled and unfilled is whether the fill character is a space of the same as the edge. Just write a unfilled routine and either chFill is a space or chEdge.

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.