1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
// Filled Box.cpp : main project file.
#include <iostream>
#include <string>
using namespace std;
int cinInRange (int low,int high, string box); // Added string variable to let user know
// what the value to input, is for.
char GetFill();
void displayBox (int numRows, int numCols, char fillchar);
int main ()
{
int rows,col;
char fill;
rows = cinInRange(3,20, "rows");
col = cinInRange(3,60, "columns");
fill = GetFill(); // Ask for displayBox fill
displayBox(rows, col, fill); // Sends all 3 variables needed to create Box
}
int cinInRange (int low, int high, string box)
{
int input = 0;
do // Do/While loop to check for input boundaries
{
cout << "Enter a number for the " << box << " between " << low << " and " << high << " : ";
cin >> input;
if (input<low || input > high)
cout << "Invalid entry. Enter a number between " << low << " and " << high << " only." << endl;
}while (input<low || input > high);
return input;
}
char GetFill()
{
char fill;
cout << "Enter a character for the interior of the box: ";
cin >> fill;
return fill;
}
void displayBox (int numRows, int numCols, char fillchar)
{
int i,j;
for (i=0;i<numCols;i++)
cout << "*"; // couts top of box
cout << endl; // Starts center of box on a new line
for (j=0; j<numRows-2;j++) // Subtract 2, 1 for top & 1 for bottom
{
cout << "*";// couts left side
for(i=0;i<numCols-2;i++)// Subtract 2, 1 for each side
cout << fillchar;
cout << "*" << endl; // couts right side and a newline
}
for (int i=0; i<numCols; i++)
cout << '*'; // couts bottom of box
cout << endl << endl; //
return;
}
|