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. #1
    Registered User jaaaaaamie's Avatar
    Join Date
    Aug 2013
    Location
    San Diego, California
    Posts
    10

    Smile 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; */
            printf("\nYour BMI is %f", &bmi);
    
    
            return 0;
    }

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Line 22 and 23:
    Code:
            bmi = (weight * 703) / (height * 2); 
            printf("\nYour BMI is %f\n", bmi);
    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. #3
    Registered User jaaaaaamie's Avatar
    Join Date
    Aug 2013
    Location
    San Diego, California
    Posts
    10
    im learning typos are extremely easy to do. Thanks for the first reply!

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Yes they are!

    And welcome to the forum jaaaamie!

  5. #5
    Registered User jaaaaaamie's Avatar
    Join Date
    Aug 2013
    Location
    San Diego, California
    Posts
    10
    thats not squaring the number... line 22 should be

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

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by jaaaaaamie View Post
    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. #7
    Registered User
    Join Date
    Jan 2011
    Posts
    141
    Quote Originally Posted by jaaaaaamie View Post
    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. #8
    Registered User jaaaaaamie's Avatar
    Join Date
    Aug 2013
    Location
    San Diego, California
    Posts
    10
    yes thanks..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple program, simple problem
    By KAUFMANN in forum C Programming
    Replies: 5
    Last Post: 02-16-2011, 01:16 PM
  2. simple program, simple error? HELP!
    By colonelhogan44 in forum C Programming
    Replies: 4
    Last Post: 03-21-2009, 12:21 PM
  3. Simple program...simple problem?
    By deadherorising in forum C Programming
    Replies: 2
    Last Post: 03-12-2009, 09:37 PM
  4. Simple program, not so simple problem
    By nolsen in forum C++ Programming
    Replies: 2
    Last Post: 01-18-2008, 10:28 AM
  5. Simple simple program
    By Ryback in forum C++ Programming
    Replies: 10
    Last Post: 09-09-2004, 06:48 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21