Thread: Help with error

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    8

    Help with error

    This program runs, but all of the values are coming out as 0.0.

    Write a program that ask the user for the radius of a circle as a float value and prints a table with the circle’s diameter, its circumference and its area. Use a const float to represent a value for PI that is equal to 3.14159.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main ()
    {
        float pi=3.14, area=0, circumference=0, diameter=0, radius=0, m=0;
        printf("Enter the raidus of a circle:\n");
        scanf("%f", &radius);
        radius = m;
        do
        {
               area=pi*m*m;
               circumference=2*(pi*m);
               diameter=2*m;
        }
        while (m!=0);
        
        printf("%f is the Area \n",area);
        printf("%f is the Circumference \n",circumference);
        printf("%f is the Diameter \n",diameter);
        
        system("pause");
        return 0;

  2. #2
    THANK YOU KINDLY SIR Phenax's Avatar
    Join Date
    Mar 2011
    Posts
    74
    Code:
        radius = m;
    Do you mean
    Code:
    m = radius;
    Quote Originally Posted by Plato
    Never discourage anyone...who continually makes progress, no matter how slow.

  3. #3
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Better yet, why not ditch the m variable and just do your calculations with radius? It will help you avoid silly errors like this, and make your code more readable.

  4. #4
    Registered User
    Join Date
    Apr 2011
    Posts
    50
    you have defined m=0 and then assigned radius=m which is actually =0 so your radius bcomes 0 and hence the error.

    moreover as the problem tells you u shuld have defined pi as const float and not float

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM