Reputation: 9
sorry if the question isn't clear enough so here I am explaining more:
#include <iostream>
using namespace std;
int main()
{
int num;
cout << "Enter a number: ";
cin >> num;
for (int y = 1; y <= num; ++y){
for (int x = 1; x <= num; ++x){
if (x == 1 || x == num || y == 1 || y == num){
cout << "* ";
}
}
cout << endl;
}
}
This piece of code is supposed to print a square shape (framed), it's doing well except for the second column is being dragged to the left with the first column. Here how it looks like (actual output):
* * * * * * * *
* *
* *
* *
* *
* *
* *
* * * * * * * *
and my expected output is supposed to look like this:
* * * * * * * *
* *
* *
* *
* *
* *
* *
* * * * * * * *
Any help? especially that I don't see any problem with my code!
Upvotes: 0
Views: 46