#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    17
    Rep Power
    0

    If statment help


    I am wanting to write a program for a BMI calculator that eventually will record details for several entries.

    However to start with I need to be able to just complete one calculation.

    Below is my code which works up to the if statement what I am trying to do is once I have completed the calculation be able to take that result and use the if statement to indicate if the result is normal, under or over.

    I don't know how to take the result and put it into the if statement.

    Code:
      #include <stdio.h>
    #include <math.h>
    int main()
    {
        
       float height, weight,bmi;
      
     
       printf("Enter Weight in Kg's and Height in METERS  \n");
       scanf("%f%f", &weight, &height );
    
       bmi = weight/(height*2);
     
    
       printf("Your BMI is %.2f\n",bmi);
       
       scanf("%");
       
      if("%f"<=25){
                    printf("your weight is normal\n");
    }
          
     
    return(0);

    Comments on this post

    • salem disagrees : xposter http://cboard.cprogramming.com/c-programming/158317-help-if-statement.html
  2. #2
  3. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,576
    Rep Power
    1906
    Try to separate the input with a space:
    Code:
     scanf("%f %f", &weight, &height );
    What do you try to do with this:
    Code:
       scanf("%");
       
      if("%f"<=25){
    You should use the proper variable (bmi) in the if-statement.
  4. #3
  5. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222
    That is utter nonsense.
    Code:
       scanf("%");
       
      if("%f"<=25){
    The scanf does nothing. And the if statement is comparing the address with 25. Since the first K or so of memory belongs to the operating system, such as the interrupt vector table, I think it's a very safe guess that that string literal, which is co-located with the program image in RAM, is far greater than memory address 25.

IMN logo majestic logo threadwatch logo seochat tools logo