Answer to Question #308789 in C++ for nickname

Question #308789
This is a straightforward program that will "draw" a rectangle using any character selected by the user. The user will also provide the width and height of the final rectangle. Use a nested for loop structure to create the output.

 

Input:

 

This program will draw a rectangle using your character of choice.
Enter any character:      [user types: *]

Enter the width of your rectangle:     [user types: 20]

Enter the height of your rectangle:     [user types: 5]

 

Output:

 

********************
********************
********************
********************

********************

1
Expert's answer
2022-03-10T02:09:56-0500
#include <iostream>
using namespace std;


int main() {
    char ch;
    int width, height;


    cout << "This program will draw a rectangle using your character of choice" << endl;
    cout << "Enter any character: ";
    cin >> ch;
    cout << "Enter the width of your rectangle: ";
    cin >> width;
    cout << "Enter the height of your rectangle: ";
    cin >> height;


    cout << endl;
    for (int i=0; i<height; i++) {
        for (int j=0; j<width; j++) {
            cout << ch;
        }
        cout << endl;
    }


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog