# simple BMI program

This is a discussion on simple BMI program within the C Programming forums, part of the General Programming Boards category; hi all..im new to this forum. I read Absolute Beginners Guide to C published in 1993 by Sams Publishing these ...

1. ## simple BMI program

hi all..im new to this forum. I read Absolute Beginners Guide to C published in 1993 by Sams Publishing these past two weeks and I have just ordered K&R. I figured i'd post my first post (created an account on this forum a few days ago). Im going to stick with learning C until I master it.

I'm compiling on mac os x 10.6.8 inside Console/X11 using gcc, says gcc version 4.2.1 (I'm aware its old).

I have read about data types and I know they aren't correct and I don't think the expression is right.

Code:
```/* bmi.c */

#include <stdio.h>

main()
{
float bmi;
float height;
int weight;

printf("Enter weight:\n ");
scanf("%d", &weight);

printf("Enter height in inches:\n ");
scanf("%f", &height);

bmi = weight * 703 / (height)2; */

return 0;
}```

2. Line 22 and 23:
Code:
```        bmi = (weight * 703) / (height * 2);
Scanf needs the & operator for non-char arrays. Printf() doesn't need the address to print out a variable's value.

Putting a \n on the end of each printf format insures that the printing will be done right away, instead of being buffered (which some systems do by default).

3. im learning typos are extremely easy to do. Thanks for the first reply!

4. Yes they are!

And welcome to the forum jaaaamie!

5. thats not squaring the number... line 22 should be

Code:
`bmi = (weight * 703) / (height * height);`

6. Originally Posted by jaaaaaamie
thats not squaring the number... line 22 should be

Code:
`bmi = (weight * 703) / (height * height);`
If you need to square the value of height, then yes, of course.

7. Originally Posted by jaaaaaamie
thats not squaring the number... line 22 should be

Code:
`bmi = (weight * 703) / (height * height);`

there is no ^ operator if thats what you were thinking to do. height^2

8. yes thanks..