Thread: Printing a circle with different symbols

  1. #1
    Registered User alpine's Avatar
    Join Date
    Oct 2010
    Posts
    6

    Printing a circle with different symbols

    Here's what i've got so far:
    Code:
    int r1, r2, x, y, hyp, i;
    	char grid [30][30];
    	
    	printf("Enter the outer radius of your wheel?\n");
    	scanf("%d", &r1);
    	printf("Enter the inner radius of your wheel?\n");
    	scanf("%d", &r2);
    	
    	i = (pow(x,2) + pow(y,2));
    	hyp = sqrt(i);
    	
    	for(x = -30; x < 30; x++) {
    		for (y = -30; y < 30; y++) {
    			if(sqrt(pow(x,2) + pow(y,2)) > r1 * 2)
    				printf(" ");
    			else if(hyp < r1 * 2 && hyp > r2 * 2)
    				printf("$");
    			else if(hyp <= r2 * 2)
    				printf("*");
    		}
    		printf("\n");
    	}
    This is what it's supposed to look like:
    Code:
       ***********         
           ***************       
          *****************      
         *******************     
        *********************    
       ***********************   
      *************************  
      *************************  
     **********$$$$$$$********** 
     *********$$$$$$$$$********* 
     ********$$$$$$$$$$$******** 
     ********$$$$$$$$$$$******** 
     ********$$$$$+$$$$$******** 
     ********$$$$+++$$$$******** 
     ********$$$$$+$$$$$******** 
     ********$$$$$$$$$$$******** 
     ********$$$$$$$$$$$******** 
     *********$$$$$$$$$********* 
     **********$$$$$$$********** 
      *************************  
      *************************  
       ***********************   
        *********************    
         *******************     
          *****************      
           ***************       
             ***********
    But all I get is a full circle of *'s can anyone help me out with the math?

  2. #2
    Registered User
    Join Date
    Aug 2010
    Posts
    230
    it probably don' t go insede the print ($)...when i had such exercises it helped to draw in paper an array and see little by little what happens...i think this is something you can easy do...just be a little patient! ...

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    This looks very dodgy:
    Code:
    if(sqrt(pow(x,2) + pow(y,2)) > r1 * 2)
    				printf(" ");
    Looking at a right angle triangle, with sides of 3, 4, & 5 - this is true:
    9 + 16 = 25 (Asqr + Bsqr) = Csqr

    but sqrt(9+16) = 5, and I don't see that necessarily equaling r1*2. (The diameter of the circle).

    Shouldn't the center of the wheel be your reference, so the radius is what you want to compare 5 with, instead?

    BTW, if you want it to look like a wheel or tire, multiply the figure times something like 2.6 (depending on the height to width ratio of your console font, and it prints out something that looks pretty good. (When it's working right, of course)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C# Printing Problem
    By silverlight001 in forum C# Programming
    Replies: 0
    Last Post: 03-23-2009, 01:13 AM
  2. Replies: 7
    Last Post: 02-02-2009, 07:27 AM
  3. Trouble with Windows/DirectX programming
    By bobbelPoP in forum Windows Programming
    Replies: 16
    Last Post: 07-08-2008, 02:27 AM
  4. Strange error?
    By MrLucky in forum C++ Programming
    Replies: 5
    Last Post: 02-04-2006, 03:01 PM
  5. point lies in circle?
    By cozman in forum Game Programming
    Replies: 3
    Last Post: 12-20-2001, 04:39 PM