Hi Guys,
I am writing a program which enables the user to enter a size for a square and then they can choose to output it in several ways, clear filled horizontal/verticals lines. The first two I have manged however the latter horizontal/vertical I cant quite get right, as they only work if the square size is 5. I understand this is because of where the asterisks are printed along x and y however I'm not sure how to write it so that it works no matter the size of the square eg. prints every other line.
Here is my code so far:
#include <iostream>
using namespace std;
int main ()
{
int x, y, i, type, option;
cout << "Please enter square size: ";
cin >> i;
cout << "Please enter its type " << endl;
cout << " 1: clear" << endl;
cout << " 2: filled" << endl;
cout << " 3: horizontal lines" << endl;
cout << " 4: vertical lines" << endl;
cout << "Type: ";
cin >> type;
cout << endl;
if (type == 2){
for (x=i; x>0; x--)
{
for (y=i; y>1; y--)
cout << "*";
cout << "*" << endl;
}
cout << endl;
}
else
if (type == 1){
for(y=0; y<i; y++)
{
cout << endl << endl;
for(int x=0; x<i; x++)
{
if ((y==0 || y==i-1) || (x==0) || (x==i-1))
{
cout << "* ";
}
else cout<<" ";
}
}
cout << endl << endl;
}
else
if (type == 3) {
for(y=0; y<i; y++)
{
cout << endl << endl;
for(int x=0; x<i; x++)
{
if ((y==0 || y==i-3) || y==i-1 || (x==0) || (x==i-1))
{
cout << "* ";
}
else cout <<" ";
}
}
cout << endl << endl;
}
else
if (type == 4) {
for(y=0; y<i; y++)
{
cout << endl << endl;
for(int x=0; x<i; x++)
{
if ((y==0 || y==i-1) || (x==0) || (x==i-1) || (x==i-3))
{
cout << "* ";
}
else cout <<" ";
}
}
cout << endl << endl;
}
cout << "Draw another square?" << endl;
cout << " 1: Yes" << endl;
cout << " 2: No" << endl;
cout << "Option: ";
cin >> option;
}
Thankyou!