Mark McIntyre <> wrote in message news:<>. ..
> On 29 Jan 2004 05:55:19 -0800, in comp.lang.c ,
> (Bob Crowley) wrote:
>
> > (EPerson) wrote in message news:<. com>...
> >>
> >
> >Sorry to get off the topic, but as an absolute beginner teaching
> >myself to program in C, I would like to know why I can get numbers to
> >add together either as declared variables, or as mathematical
> >functions in "printf", but find I cannot get them to multiply or
> >divide.
>
> You're using the operators * and / to do multiplication and division,
> right?
>
>
> --
> Mark McIntyre
> CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
> CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
>
>
> ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
> http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
> ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
The problem is in a text book I am using, namely to find out
"5/12*68".
My coding is as follows
#include <stdio.h>
#include <math.h> COMMENT - should not be necessary
main(){
float answer;
answer = 5/12*68;
printf("Five eighths of sixty eight is %f\n", answer);
}
END OF CODING
The first time I tried it I did not use a variable, but simply had
5/12*68 in the printf statement where the variable name "answer" is
now.
I either got 0.000000 or -1.9xxxxx as the answer, whereas it should be
28+.
I also changed the / and * signs to + to see what would happen, and
got 85 which is correct. So the program worked when I used the +
signs for addition, but not when I used / or * for division and
multiplication.
I am using Redhat Linux 8, with the gcc C compiler, and compiling with
gcc -o object.o source.c
As I said, I'd appreciate knowing why the program won't allow * or /
to work.
Bob Crowley.