5 Replies - 4705 Views - Last Post: 11 February 2010 - 09:06 AM Rate Topic: -----

#1 samhutto  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 27-August 09

C: BMI calculator stuck in do-while loop

Posted 10 February 2010 - 11:09 PM

Hey I'm having a problem with my BMI calculation program. The program is made to find a person's BMI given their weight and height(within a certain range), then find their target weight based on their desired BMI. Lastly it uses a formula to find their ideal body weight based on their gender and previously mentioned height.
I don't get any errors when compiling, but when i run the program, it just gets stuck in the do-while loop(from lines 64-69) that deals with the person's gender. no matter what I enter for the person's gender, it just asks for it again. Do you see what it might be?
Thanks!


*/
#include <stdio.h>
#include <math.h>
    int main()
   {
      double pounds=0, kg=0, height=0, bmi=0, meter=0, dBMI=0, tKG=0, weight=0, IBW=0;
      char gender=0, m=0, f=0;
   
   
   // Read in weight of person in pounds
   
      do
      {
         printf("Enter the weight of the person in pounds (between 90 and 350).\n");
         scanf("%lf", &pounds);
      }
      while( pounds <= 90.0 || pounds >= 350.0);
   	
   // Read in the height of person in inches 
   	
      do
      {
         printf("Enter the height of the person in inches (between 59 and 78).\n");
         scanf("%lf", &height);
      }
      while (height <= 59.0 || height >= 78.0);
      
      kg=pounds/2.2046;
      meter=height*.0254;
         
      bmi = kg/(meter*meter);
      
      printf("The BMI is: %.2lf.", bmi);
   // Read in the desired BMI
   	
      do
      {
         printf("\n\nEnter the desired BMI (between 18.5 and 30).\n");
         scanf("%lf", &dBMI);
      }
      while (dBMI <=18.5 || dBMI >=30);
   
   
      tKG = dBMI*(meter*meter);
      weight = tKG*2.2046;
   	
      printf("The target weight is: %.2lf.\n", weight);
   	//Read in the person's gender
   
      do
      {
         printf("\nIs the person a male or female? Enter m or f:\n");
         scanf(" %c", &gender);
      }
      while (gender != m || gender != f);
   	
   	//Compute IBW according to gender
      if (gender == m)
      {
         IBW = 50.0 + 2.3 * (meter - 60.0);
         printf("The ideal weight is: %lf.", IBW);
      }
      else if (gender == f)
      {
         IBW = 45.5 + 2.3 * (meter - 60.0);
         printf("The ideal weight is: %lf.", IBW);
      }
   	
      return 0;
   }


This post has been edited by JackOfAllTrades: 11 February 2010 - 06:19 AM


Is This A Good Question/Topic? 0
  • +

Replies To: C: BMI calculator stuck in do-while loop

#2 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: C: BMI calculator stuck in do-while loop

Posted 10 February 2010 - 11:12 PM

Please edit your post to add the code tags around your code:

:code:

Thanks!
Was This Post Helpful? 0
  • +
  • -

#3 PlasticineGuy  Icon User is offline

  • mov dword[esp+eax],0
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,436
  • Joined: 03-January 10

Re: C: BMI calculator stuck in do-while loop

Posted 10 February 2010 - 11:21 PM

do
{
printf("\nIs the person a male or female? Enter m or f:\n");
scanf(" %c", &gender);
}
while (gender != m || gender != f);
First, you're checking variables m and f which are equal to 0, not 'm' and 'f' (the characters). Second, you should use &&, not ||.

This post has been edited by PlasticineGuy: 10 February 2010 - 11:26 PM

Was This Post Helpful? 1
  • +
  • -

#4 Guest_subrat*


Reputation:

Re: C: BMI calculator stuck in do-while loop

Posted 11 February 2010 - 12:08 AM

do
{
printf("\nIs the person a male or female? Enter m or f:\n");
scanf("%c", &gender);
}
while (gender != 'm' && gender != 'f');

//Compute IBW according to gender
if (gender == 'm')
{
IBW = 50.0 + 2.3 * (meter - 60.0);
printf("The ideal weight is: %lf.", IBW);
}
else if (gender == 'f')
{
IBW = 45.5 + 2.3 * (meter - 60.0);
printf("The ideal weight is: %lf.", IBW);
}

return 0;
}

This post has been edited by JackOfAllTrades: 11 February 2010 - 06:20 AM
Reason for edit:: Added code tags.

Was This Post Helpful? 1

#5 PlasticineGuy  Icon User is offline

  • mov dword[esp+eax],0
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,436
  • Joined: 03-January 10

Re: C: BMI calculator stuck in do-while loop

Posted 11 February 2010 - 01:26 AM

Don't write code for people.
Was This Post Helpful? 0
  • +
  • -

#6 samhutto  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 27-August 09

Re: C: BMI calculator stuck in do-while loop

Posted 11 February 2010 - 09:06 AM

View PostPlasticineGuy, on 10 February 2010 - 10:21 PM, said:

do
{
printf("\nIs the person a male or female? Enter m or f:\n");
scanf(" %c", &gender);
}
while (gender != m || gender != f);
First, you're checking variables m and f which are equal to 0, not 'm' and 'f' (the characters). Second, you should use &&, not ||.



Thanks very much! That helps a ton
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1