Thread: code probs

  1. #1
    Blaher yeah's Avatar
    Join Date
    Feb 2005
    Posts
    21

    Cool code probs

    hey,

    i have a little problem with this:

    Code:
    #include <stdio.h>
    
    int main()
    {
        int radius;
    
        printf("Enter the radius of circle: ");
        scanf("%u",&radius);  /* & is the "address of" operator. 
                        The address of radius is passed into scanf. Passing 
                        the address of a variable is equivalent to passing 
                        a pointer containing the address of the variable. */
        printf("A circle of radius %u has area %u\n",radius,3.14*radius*radius);
    
        return(0);
    }
    it doesnt complie!!

    thanks,
    Yeah

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    What do you mean it doesn't compile? What error do you get? I get one warning because you're printing a float as an integer.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User xxxrugby's Avatar
    Join Date
    Jan 2005
    Posts
    178
    Code:
    #include <stdio.h>
    
    int main()
    {
        unsigned int radius; unsigned int n;
    
        printf("Enter the radius of circle: ");
        scanf("%u",&radius); 
        n = 3.14*radius*radius;
        printf("A circle of radius %u has area %u\n",radius, n);
        
        return(0);
    }
    Last edited by xxxrugby; 02-11-2005 at 06:32 PM.
    Sorry for spelling errors, not English!
    xxxrugby: "All Human Race Will Die From My Hand!"
    xxxrugby: "We are all philosophers, when question is about politics!"

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    184
    you can try this bit of code

    Code:
    #include <stdio.h>
    
    int main()
    {
        int radius;
    
        printf("Enter the radius of circle: ");
        scanf("%u",&radius);  
        printf("A circle of radius %u has area %.2f\n",radius,3.14*radius*radius);
    
        return;
    }

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    It's like the blind leading the blind...

    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Quote Originally Posted by quzah
    It's like the blind leading the blind...

    Quzah.

    I feel your pain... <shakes head> I feel your pain.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  7. #7
    Blaher yeah's Avatar
    Join Date
    Feb 2005
    Posts
    21
    Originally Posted by quzah
    It's like the blind leading the blind...

    Quzah.
    what did i do?

    and

    thanks a lot, you are the best, xxxrugby!!

  8. #8
    Blaher yeah's Avatar
    Join Date
    Feb 2005
    Posts
    21
    ok,

    it works, but
    i want it to go to the nearest hundreth, not the nearest whole number!
    can you help?

  9. #9
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    The answer was in the very first reply to this thread. Warnings do actually mean something and as soon as you fix that warning in your original code then you'll get the correct answer.

    You look at xxxrugby's code like it's good, but it's only leading you in the wrong direction. At the very best it's a workaround for your original problem. Not a solution.
    If you understand what you're doing, you're not learning anything.

  10. #10
    Registered User xxxrugby's Avatar
    Join Date
    Jan 2005
    Posts
    178
    Have you tried use float insted of int.
    f - decimal format output

    Code:
    #include <stdio.h>
    
    int main()
    {
        float radius; float n;
        printf("Enter the radius of circle: ");
        scanf("%f",&radius); 
        if(radius < 0) {radius = radius * (-1);}  /* this is insted declaring unsigned is for decimal int */
        n = 3.14*radius*radius;
        printf("A circle of radius %f has area %f\n",radius, n); 
        return(0);
    }
    Last edited by xxxrugby; 02-12-2005 at 06:39 AM.
    Sorry for spelling errors, not English!
    xxxrugby: "All Human Race Will Die From My Hand!"
    xxxrugby: "We are all philosophers, when question is about politics!"

  11. #11
    Blaher yeah's Avatar
    Join Date
    Feb 2005
    Posts
    21
    i tryed a float thing before and it said "non-float" so i changed it and it worked, but i am going to try yours first!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Proposal: Code colouring
    By Perspective in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 05-14-2007, 07:23 AM
  2. Updated sound engine code
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 11-18-2004, 12:38 PM
  3. windows console code probs
    By henroid815 in forum C++ Programming
    Replies: 1
    Last Post: 05-04-2003, 05:53 PM
  4. Math function code - couple probs, tips?
    By Captain Penguin in forum C++ Programming
    Replies: 4
    Last Post: 06-18-2002, 09:54 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM