# How do you make this BMI calculator work?

• (2 Pages)
• 1
• 2

## 26 Replies - 1850 Views - Last Post: 20 March 2014 - 05:29 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=342753&amp;s=6cbf4e09e1f3c42974b3fa21b3c7db31&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

Reputation: 0
• Posts: 17
• Joined: 20-March 14

# How do you make this BMI calculator work?

Posted 20 March 2014 - 12:29 PM

What am I doing wrong here?
i honestly can find the answer.

```// ConsoleApplication7.cpp : Defines the entry point for the console application.
//

#include <stdio.h>

int main(void)
{

int inches, pounds;
float BMI;

printf("\nWhat is your height in inches:", inches);
scanf_s("%d", &inches);

printf("\nWhat is your weight in pounds:", pounds);
scanf_s("%d", &pounds);

BMI=((float)(pounds*703)/(float)(inches*inches));

printf("Your BMI is: %.2f \n", BMI);

}

```

Is This A Good Question/Topic? 0

## Replies To: How do you make this BMI calculator work?

### #2 modi123_1

• Suitor #2

Reputation: 14045
• Posts: 56,218
• Joined: 12-June 08

## Re: How do you make this BMI calculator work?

Posted 20 March 2014 - 12:36 PM

Explain what's wrong. Is there an error? If so what is the error? Is it not working as expected? If so what is it doing and explain what it should be doing.

Reputation: 0
• Posts: 17
• Joined: 20-March 14

## Re: How do you make this BMI calculator work?

Posted 20 March 2014 - 12:47 PM

It says theres errors but it does not show me what the errors are.

Error 1 error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source? c:\users\shaun berdugo\documents\visual studio 2012\projects\consoleapplication4\consoleapplication4\consoleapplication4.cpp 26

thats the error it is giving me

### #4 infernorthor

• D.I.C Lover

Reputation: 362
• Posts: 1,718
• Joined: 07-February 14

## Re: How do you make this BMI calculator work?

Posted 20 March 2014 - 12:53 PM

Well that seems pretty clear of the error. Include "stdafx.h"

If you did, and if I remember correctly an extra return in your header file should fix it.

### #5 AKMafia001

• </code.in.dream>

Reputation: 238
• Posts: 738
• Joined: 11-June 11

## Re: How do you make this BMI calculator work?

Posted 20 March 2014 - 12:53 PM

What compiler are you using?

scanf_s is Microsoft specific.

Reputation: 0
• Posts: 17
• Joined: 20-March 14

## Re: How do you make this BMI calculator work?

Posted 20 March 2014 - 12:56 PM

error C4700: uninitialized local variable 'inches' used

now its giving me this error for inches and pounds.

and i'm using C

### #7 modi123_1

• Suitor #2

Reputation: 14045
• Posts: 56,218
• Joined: 12-June 08

## Re: How do you make this BMI calculator work?

Posted 20 March 2014 - 12:57 PM

Quote

uninitialized local variable 'inches' used

So initialize them! Give them a value!

Reputation: 0
• Posts: 17
• Joined: 20-March 14

## Re: How do you make this BMI calculator work?

Posted 20 March 2014 - 12:58 PM

I'm using microsoft with visual studios 2012

### #9 no2pencil

• Professor Snuggly Pants

Reputation: 6636
• Posts: 30,907
• Joined: 10-May 07

## Re: How do you make this BMI calculator work?

Posted 20 March 2014 - 01:05 PM

My guess : You found this code online, & hoped it would just work. The reason you have those errors is because of scanf_s, which do not go to your compiler (as suggested by AKMafia001).

```\$ make test

cc     test.c   -o test
/tmp/cc70WHcH.o: In function `main':
test.c:(.text+0x31): undefined reference to `scanf_s'
test.c:(.text+0x5e): undefined reference to `scanf_s'
collect2: ld returned 1 exit status
make: *** [test] Error 1

```

So I removed the scanf_s ...

```\$ vi test.c
```

Now it compiles :

```\$ make test
cc     test.c   -o test

```

& works :

Quote

./test

What is your height in inches:

Reputation: 0
• Posts: 17
• Joined: 20-March 14

## Re: How do you make this BMI calculator work?

Posted 20 March 2014 - 01:08 PM

most of it i typed up, but some bits and pieces were pulled from sites to see if it would correct it.

but my teacher tells me that scanf_s is the one that we always use for things like this.

### #11 no2pencil

• Professor Snuggly Pants

Reputation: 6636
• Posts: 30,907
• Joined: 10-May 07

## Re: How do you make this BMI calculator work?

Posted 20 March 2014 - 01:09 PM

In that case I would suggest that you ask your teacher what compiler you are using, or how to properly initialize your project.

• Saucy!

Reputation: 6246
• Posts: 24,014
• Joined: 23-August 08

## Re: How do you make this BMI calculator work?

Posted 20 March 2014 - 01:13 PM

scanf_s is a Microsoft extension for "securing" scanf. Where the OP says

Quote

I'm using microsoft with visual studios 2012

They're fine there.

### #13 no2pencil

• Professor Snuggly Pants

Reputation: 6636
• Posts: 30,907
• Joined: 10-May 07

## Re: How do you make this BMI calculator work?

Posted 20 March 2014 - 01:16 PM

As per the MSDN, their example of scanf_s uses two headers & you only have the one :

```#include <stdio.h>
#include <stdlib.h>
```

Try with those. I can't verify, as I don't have that compiler. Sorry.

Reputation: 0
• Posts: 17
• Joined: 20-March 14

## Re: How do you make this BMI calculator work?

Posted 20 March 2014 - 01:17 PM

yeah this is my first programming class haha.

how to i initialize and give them values?

### #15 AKMafia001

• </code.in.dream>

Reputation: 238
• Posts: 738
• Joined: 11-June 11

## Re: How do you make this BMI calculator work?

Posted 20 March 2014 - 01:19 PM

> how to i initialize and give them values?
How would you give a variable a value?