Hello everyone.
I am currently writing a program for class.
the criteria of the program is as follows.
1# write a program that reads in the size of a square and then prints a hollow square of that size out of asterisks.
The program should work for all square sizes between 1 to 20. If the user enters a non valid number ask the user to re-enter it.Also the program should allow the user to create as many squares as the would like before ending the program.
I am having a difficult time figuring out how to hollow the square, as well as getting it to loop the whole process over. Any advice would be greatly appreaciated.
#include <iostream>
#include <iomanip>
using namespace std;
Hi, basic problem is that you can't simply 'draw' a symmetric square, because lines and rows in console isn't equally long. So you each time get rectangle. Well, following code should do what you need:
int main ()
{
int square_size;
char full;
do
{
cout << "Enter square size: ";
cin >> square_size;
while(square_size < 1 || square_size > 21)
{
cout<< "Size must be between 1 and 20, Enter square size: ";
cin >> square_size;
}
cout << "Do you want full square (y/n)?\n";
cin >> full;
cout << "\n\n\n";
if (full == 'Y') full = 'y';
int b;
if (full != 'y')
{
for (b = 0; b < square_size; ++b)
cout.put('*');
cout << endl;
for (int a = 2; a < square_size; ++a)
{
cout.put('*');
for (b = 2; b < square_size; ++b)
cout.put(' ');
cout.put('*');
cout << endl;
}
for (b = 0; b < square_size; ++b)
cout.put('*');
}
elsefor (int a = 0; a < square_size; ++a)
{
for (b = 0; b < square_size; ++b)
cout.put('*');
cout.put('\n');
}
cout<< "\n\nwould you like to draw another square (y or n): ";
cin.ignore(100, '\n');
}
while (cin.get() == 'y');
return 0;
}