help with loops please

This is a discussion on help with loops please within the C Programming forums, part of the General Programming Boards category; im trying to get this to run a scan of user enterd stats then calculate the body mass index's of ...

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    2

    help with loops please

    im trying to get this to run a scan of user enterd stats then calculate the body mass index's of the height in increments of 3 inches with weight in increment of 10's and say whether they are statistically overweight, like this :

    5 3 150 26.5684 overweight
    5 3 160 28.3396 overweight
    5 6 140 22.5941 not overweight
    5 6 150 24.2080 not overweight


    here is what i have, but i cant find the errors is compiles in lines 66 and 107, any help would be greatly appreciated

    Code:
    #include <stdio.h>
    #include <math.h>
    
    int main()
    {
      
    int i,  /* inches variable2  */
    
        loheightfeet, /* low height in feet and inches*/
    
        hiheightfeet,  /* high height in feet and inches*/
    
        loweight,      /*  low weight in pounds */
    
        hiweight,       /*  high weight in pounds */
    
        inches;       /* height in inches */
    
      float bmi;      /* bmi */
    
    
    
      /* get height and weight */
    
      printf("Please enter low height in feet: ");
    
      scanf("%d", &loheightfeet);
    
      printf("please enter high height in feet: ");
      
      scanf("%d", &hiheightfeet);
    
      printf("Please enter low weight in pounds: ");
    
      scanf("%d", &loweight);
    
      printf("Please enter high weight in pounds: ");
    
      scanf("%d", &hiweight);
      
     
       for( i=inches, i<= hiheightfeet * 12, i=i+3){
           
                  
    
        printf(" %d/12    %num         ", inches);   
    
    
    
          while( loweight <= hiweight ) {
    
    
    
            /* calculate BMI */
    
            inches = loheightfeet * 12;
     
            bmi = 703.0 * loweight / (float) (inches * inches);
        
    
            /* add 5 to loweight */
    
            loweight = loweight +10;
        
    
    
    
            /* indicate whether user is overweight */
    
              if (bmi > 25.0) {
    
                printf(" %d        %.4f        overweight.\n", loweight, bmi);
              }
    
              if (bmi < 25.0) {
    
                printf(" %d        %.4f       not overweight.\n", loweight, bmi );
     
       
              } 
        
           } 
                
                printf("/n")
        } 
       return 0;
    }

  2. #2
    Registered User
    Join Date
    Oct 2007
    Posts
    2
    the main problem is the for loop, is there something wrong with it?

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,793
    Code:
    int loheightfeet, /* low height in feet and inches*/
    
        hiheightfeet,  /* high height in feet and inches*/
    
        loweight,      /*  low weight in pounds */
    
        hiweight,       /*  high weight in pounds */
    
        inches;       /* height in inches */
    
    float bmi;      /* bmi */
    
    
    
      /* get height and weight */
    
      printf("Please enter low height in feet: ");
    
      scanf("&#37;d", &loheightfeet);
    
      printf("please enter high height in feet: ");
      
      scanf("%d", &hiheightfeet);
    
      printf("Please enter low weight in pounds: ");
    
      scanf("%d", &loweight);
    
      printf("Please enter high weight in pounds: ");
    
      scanf("%d", &hiweight);
      
     
       for( i=inches, i<= hiheightfeet * 12, i=i+3){
    Where is inches ever initialized? And yes, you've got a problem with the for loop besides the uninitialized inches variable, those commas should be semicolons.

    May be some other things but I just took a very quick glance.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Double-spacing your source code does not make it any easier to read. In fact, in my opinion it makes it even harder to read. (If this is because you switched line endings, then you can't help it, though.)
    Code:
    printf("/n")
    No doubt you mean \n, not /n. And you need a semicolon after that statement as well.

    Code:
            /* add 5 to loweight */
    
            loweight = loweight +10;
    5, 10, what's the diff?

    Code:
              if (bmi > 25.0) {
    
                printf(" &#37;d        %.4f        overweight.\n", loweight, bmi);
              }
    
              if (bmi < 25.0) {
    
                printf(" %d        %.4f       not overweight.\n", loweight, bmi );
     
       
              }
    So if bmi is exactly 25.0, the user isn't even granted a message? I suggest using an else clause.

    Code:
        printf(" %d/12    %num         ", inches);
    Percent signs (%) have special meanings with printf(). If you meant to print a literal %, use %% -- because while %n is a valid (if uncommon) format specifier, it requires that you pass another argument to printf() to use it.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Loops Trouble
    By rlframpton in forum C Programming
    Replies: 2
    Last Post: 04-17-2009, 01:08 AM
  2. Too many loops D:
    By F5 Tornado in forum C++ Programming
    Replies: 6
    Last Post: 12-03-2007, 12:18 AM
  3. help with arrays and loops
    By jdiazj1 in forum C Programming
    Replies: 4
    Last Post: 11-24-2001, 03:28 PM
  4. for loops in C
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 10-15-2001, 05:09 PM
  5. exiting loops with ease?
    By KingRuss in forum Game Programming
    Replies: 3
    Last Post: 09-24-2001, 08:46 PM

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