Amazing, thank you for your reply. As of right now, I'm going over your solutions and trying to understand them first before I use them. First of all, in your first solution, I understand everything up until here:
1 2 3 4 5 6
|
int circle_radius = 10; // or whatever you want
for (int i = 0; i <= 2*circle_radius; i++)
{
for (int j = 0; j <= 2*circle_radius; j++)
{
|
When I was trying to create a nested for-loop for the circle, it would never occur to me to multiply the circle_radius by 2. More importantly, it wouldn't occur to me to use the circle_radius in the condition in the first place. I thought I had to do something similar to this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
int i,j,k;
for( i = 10; i >= 1; i-- )
{
for( j = 1; j < i; j++ )
{
cout << " ";
}
for( k=10; k >= j*2; k-- )
{
cout << "*";
}
cout << "\n";
}
|
This creates the upper part of a diamond I think. I thought I had to put conditions like
i >= 1, j < i, and k >= j*2 |
I barely understand why those conditions were used for the upper part of the diamond so you can imagine how I feel about the circle_radius. If you could explain a bit on why you use the circle_radius in the conditions I would really appreciate it (I'm debugging it using the Step Over function in VB so I can understand it). Now for the rest of that code, the if else statement surprised me. How did you get it?
1 2 3 4 5 6 7 8
|
if (distance_to_centre > circle_radius-0.5 && distance_to_centre < circle_radius+0.5)
{
cout << "*";
}
else
{
cout << " ";
}
|
Sorry if I'm asking a lot of questions, I just really want to understand how to get a circle out of for-loops. Thank you again!