4 Replies - 383 Views - Last Post: 08 October 2011 - 08:22 AM Rate Topic: -----

#1 amen69  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 08-October 11

i get 0 for my bmi calculator answer can you help me whats wrong with?

Posted 08 October 2011 - 08:08 AM

#include <stdio.h>


int main(void)
{
    float kg;
    float cm;
    int sum;



    printf("Enter your weight in kg\n");
    scanf("%f",&kg);

    printf("Enter your height in cm\n");
    scanf("%f",&cm);


    sum = (kg)/(cm*cm);

    printf("Sum is %d\n",sum);

    return 0;
}


MOD EDIT: Added code tags. When posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 08 October 2011 - 08:09 AM


Is This A Good Question/Topic? 0
  • +

Replies To: i get 0 for my bmi calculator answer can you help me whats wrong with?

#2 jimblumberg  Icon User is online

  • member icon


Reputation: 3987
  • View blog
  • Posts: 12,298
  • Joined: 25-December 09

Re: i get 0 for my bmi calculator answer can you help me whats wrong with?

Posted 08 October 2011 - 08:14 AM

What did you input into your program?

If you want sum to show any fractional amounts you will need to make sum a floating point number.

Jim
Was This Post Helpful? 1
  • +
  • -

#3 Karel-Lodewijk  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 449
  • View blog
  • Posts: 849
  • Joined: 17-March 11

Re: i get 0 for my bmi calculator answer can you help me whats wrong with?

Posted 08 October 2011 - 08:15 AM

2 problems.

1) BMI is kg/m^2, not kg/cm^2.

2) Because of the wrong formula you will always get a bmi < 1 which when stored in an int will be rounded down, you probably want sum to be a float as well.
Was This Post Helpful? 1
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6033
  • View blog
  • Posts: 23,415
  • Joined: 23-August 08

Re: i get 0 for my bmi calculator answer can you help me whats wrong with?

Posted 08 October 2011 - 08:15 AM

Your formula for BMI calculation is wrong.
Was This Post Helpful? 0
  • +
  • -

#5 FatalTouch  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 30
  • Joined: 07-October 11

Re: i get 0 for my bmi calculator answer can you help me whats wrong with?

Posted 08 October 2011 - 08:22 AM

This is your typical BMI program...

	#include <stdio.h>
	 
	 
	int main()
	{
	    float kg;
	    float cm;
	    float sum;


 
    printf("Enter your weight in kg\n");
	    scanf("%f",&kg);
	 
	    printf("Enter your height in cm\n");
	    scanf("%f",&cm);
	 
	    sum = (kg)/((cm*cm)/10000);
	 
	    printf("BMI is %f\n",sum);
	 
	    return 0;
	}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1