1: //draw_box.cpp
2: //Displays an empty box. User chooses the size, the border character,
3: //and the indentation. Illustrates sequential loops.
5: #include <iostream>
6: #include <iomanip>
7: using namespace std;
9: int main()
10: {
11: cout << "\nThis program draws an \"empty\" box on the display. "
12: "Box \"height\" refers to\nthe number of lines and \"width\" "
13: "refers to the number of character widths.\n\n";
15: int width, height;
16: char ch;
17: int indentLevel;
19: cout << "Enter width, then height, of box: ";
20: cin >> width >> height; cin.ignore(80, '\n');
21: cout << "Enter character to be used for the box border: ";
22: cin >> ch; cin.ignore(80, '\n');
23: cout << "Enter the number of spaces to indent the box: ";
24: cin >> indentLevel; cin.ignore(80, '\n'); cout << endl;
26: int charCount;
27: cout << setw(indentLevel) << "";
28: for (charCount = 1; charCount <= width; charCount++)
29: cout << ch;
30: cout << endl;
31: for (int line = 2; line <= height-1; line++)
32: {
33: cout << setw(indentLevel) << "";
34: cout << ch << setw(width-2) << "" << ch << endl;
35: }
36: cout << setw(indentLevel) << "";
37: for (charCount = 1; charCount <= width; charCount++)
38: cout << ch;
39: cout << endl << endl;
40: }