Thread: No Output No Error what's wrong in the code

  1. #1
    Registered User
    Join Date
    Feb 2012
    Location
    India
    Posts
    4

    No Output No Error what's wrong in the code

    Its a Question in the book of
    PROGRAMMING IN ANIC C
    the question is :-

    Given the radius of a circle, write a program to compute and display its area.
    Use a symbolic constane to define the ∏(pi) value and assume a suitable value for radius.


    my Answer

    Code:
    /*  
    Name: mkbutan  
    Copyright:   
    Author:   
    Date: 03/08/12 13:50  
    Description: exec 1.5 pg 21 New
    */
    #include<stdio.h>
    #include<conio.h>
    void main()
    {
         int r,x;     
    float pi;     
    /*printf("Enter the Radius : \n",r);     
    scanf("%d",r);*/     
    pi = (22/7);     
    r = 5;    
     x = (pi*r*r);     
    printf("The Area of a Circle is : %d",x);     
    getch();     
    }
    but i dont get any output and there is no error


    pl help

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Some modern compilers reject void main(), so will refuse to compile your code. Main actually returns int. Also, a fair few compilers also do not recognise <conio.h> and the getch() function, so will refuse to compile your code.

    If the compiler does not successfully compile your code, it cannot be run, so cannot produce output.

    If you are attempting to run your program from an IDE, you need to pay attention. Just telling the IDE to run does not magically repair faulty code and execute your program. When compilers emit error messages, they are usually displayed in some window or part of the screen managed by the IDE. Your not looking at the error messages does not change that fact.

    Also, the value 22/7 is computed using integer arithmetic, so your value of pi will have the value of 3. Even if the calculation was done as floating point, 22/7 is still a poor approximation of pi (it is only accurate to within two decimal places).
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    My personal favorite approximation of pi is 355/113.0 ... quite easy for the precision you get.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    What happened to the "define a symbolic constant"?

    Maybe you want #define PI 3.14159 or const double Pi = 3.14159

    The assignment is short, but you're taking it too lightly. Perhaps take a break and get back to it when you're fresher.

  5. #5
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    on linux, if you don't have a '\n' as the last output in your printf, the buffer doesn't get flushed imediately and you don't see anything until it sees a \n, fflush(stdout) or the program terminates. but your output would be shown after you hit a character and passed the getc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with an error in the output of my code!
    By justiliang in forum C Programming
    Replies: 11
    Last Post: 09-24-2011, 09:29 AM
  2. Replies: 3
    Last Post: 05-11-2011, 02:53 PM
  3. Replies: 7
    Last Post: 12-08-2010, 04:36 PM
  4. Error in my code...not sure what i did wrong
    By Gart08 in forum C Programming
    Replies: 24
    Last Post: 11-28-2010, 11:54 AM
  5. Replies: 7
    Last Post: 08-06-2004, 09:14 AM