Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Hellp with nested loops please!

nested loop loop

  • Please log in to reply
No replies to this topic

#1 rvega

rvega

    CC Lurker

  • Just Joined
  • Pip
  • 6 posts

Posted 14 October 2010 - 11:00 AM

Hi!

I am trying to get this code to print a wheel on the screen. it is kind of printing sideways. could you please look at it and tell me whats wrong?

int main() 
{

  int distance, x, y;
 

  // Loop through each row.
  
  for (y=-20; y<=20; y++)
  
    for (x=-20; x <= 20; x++)
	{
	if (x*x + y*y >= 20*20)
	      printf(" ");
	else if (x*x + y*y < 2)
		printf("+");
	else if (x*x + y*y <= 6*6)
	printf("$");
	else
	printf("*");
    }
system("pause");
  return 0;
}

It needs to print something like this:

***********
***************
*****************
*******************
*********************
***********************
*************************
*************************
**********$$$$$$$**********
*********$$$$$$$$$*********
********$$$$$$$$$$$********
********$$$$$$$$$$$********
********$$$$$+$$$$$********
********$$$$+++$$$$********
********$$$$$+$$$$$********
********$$$$$$$$$$$********
********$$$$$$$$$$$********
*********$$$$$$$$$*********
**********$$$$$$$**********
*************************
*************************
***********************
*********************
*******************
*****************
***************
***********

Edited by dargueta, 26 October 2010 - 08:00 PM.
Added code tags

  • 0





Also tagged with one or more of these keywords: nested loop, loop

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download