Hello snew18,
Your while does the job, but it can be written simply as
while (height < 2 || height > 40)
. The extra ()s are not needed, but OK if you leave them.
You will also need another while loop, which I put first:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
while (!std::cin) // <--- If something other than a number was entered.
{
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // <--- Requires header file <limits>.
std::cout << "Input not understood. Enter width 2 to 40: ";
std::cin >> width; // <--- Changed.
}
while (width < 2 || width > 40)
{
std::cout << "Input not understood. Enter width 2 to 40: ";
std::cin >> width; // <--- Changed.
}
|
The same concept will work for "height".
This is a simple way of presenting two parts. The first is if anything other than a number is entered, formatted input, and second if the value is out of the range.
Line 47 the use of the comma operator will not work the way you are thinking. In this case "output" will end up with the value of 'n'. Actually for what you are not doing here I would remove line 47. By leaving it "output" is set equal to 'n', so inside the for loop you will always enter the if statement and never reach the else statement.
Starting withe the first function "printRepeat" this will produce a nicer looking rectangle:
std::cout << c << ' ';
.
The "printSolidRectangle" function works, but the "printHollowRectangle" does not.
From what I am remembering printing a hollow rectangle will require nested for loops. The outer to count the rows and the inner to deal with the columns. I have not found the code that I was looking for yet. You can do a search here and should find something that will work.
line 49 the for loop should be based on "height" not "width" because this for loop would need to deal with the number of lines. Although this will cause a problem with the hollow rectangle. I would say that calling the two functions with "height" and "width" and deal with the rows and columns in those functions.
Hope that helps,
Andy