How do you make this BMI calculator work?

  • (2 Pages)
  • +
  • 1
  • 2

26 Replies - 1850 Views - Last Post: 20 March 2014 - 05:29 PM Rate Topic: -----

#1 AgentShady   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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   User is offline

  • Suitor #2
  • member icon



Reputation: 14045
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#3 AgentShady   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

#4 infernorthor   User is offline

  • D.I.C Lover

Reputation: 362
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#5 AKMafia001   User is offline

  • </code.in.dream>
  • member icon

Reputation: 238
  • View blog
  • 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.
Was This Post Helpful? 1
  • +
  • -

#6 AgentShady   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

#7 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14045
  • View blog
  • 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!
Was This Post Helpful? 0
  • +
  • -

#8 AgentShady   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

#9 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6636
  • View blog
  • 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:

Was This Post Helpful? 0
  • +
  • -

#10 AgentShady   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#11 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6636
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#12 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6246
  • View blog
  • 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.
Was This Post Helpful? 1
  • +
  • -

#13 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6636
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#14 AgentShady   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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?
Was This Post Helpful? 0
  • +
  • -

#15 AKMafia001   User is offline

  • </code.in.dream>
  • member icon

Reputation: 238
  • View blog
  • 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?
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2