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:
********************
********************
********************
********************
********************
#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;
}
Comments
Leave a comment