delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/09/01/20:01:20

From: Erik Max Francis <max AT alcyone DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: working out circumference help
Date: Mon, 01 Sep 1997 13:16:46 -0700
Organization: Alcyone Systems
Lines: 49
Message-ID: <340B22AE.561D08E0@alcyone.com>
References: <01bcb6e0$041efb00$LocalHost AT rossa>
NNTP-Posting-Host: newton.alcyone.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Ross Boast wrote:

>          Yep its me again and once again i need help (with djgpp that
> is:).

Your problems are actually not specific to C.  They are standard C
questions.

> int a,b;

Since you ultimately want to print a floating point value, you should
declare a and b as double.

> scanf("%i", &a);

To make this work with doubles, you'd have to use 

    scanf("%lf", &a);

> b = (a,2) * PI;

This isn't the way to do multiplication.  You mean:

    b = 2*a*PI;

> printf ("The circumference of the circle is %i\n\n");

There is no argument passed to printf to correspond to the format
specifier here.  In any case, since you should be using floating point,
the format should be %f:

    printf("The circumference of the circle is %f\n", b);

Note that the format specifiers _are_ different for printf and scanf. 
%f is a float in scanf, %lf is a double in scanf.  In printf, variable
arguments are automatically promoted, so %f is for both float and
double.

> Thanks in advance.

My advice to you is to get a good book on ANSI C and read up some more.

-- 
          Erik Max Francis, &tSftDotIotE / mailto:max AT alcyone DOT com
                        Alcyone Systems / http://www.alcyone.com/max/
   San Jose, California, United States / icbm://37.20.07n/121.53.38w
                                      \
                  "War is like love; / it always finds a way."
                                    / Bertolt Brecht

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019