Skip to main content
November 3, 2013
Question

Help with Weight Calculator (Metric and Imperial)

  • November 3, 2013
  • 1 reply
  • 701 views

http://imageshack.us/a/img59/6380/qeup.png

http://imageshack.us/a/img203/7864/9zur.png

So, long story short, here is what I've learned to use so far: if/else statements, while/for loops, and counters. I need to create a Weight Calculator that allows me to choose to enter in Metric or Imperial IBM. I also need to determine the Height in metres or inches. Regardless, I am stumped; I do not know how to start the program let alone complete it. This is the code I have so far:

"var body_txt:TextField = new TextField();

body_txt.x = 225;

body_txt.y = 300;

body_txt.autoSize = TextFieldAutoSize.LEFT;

var myFormat:TextFormat= new TextFormat();

var yourName:String;

var yourSystem:String;

var yourHeight:String;

var total:Number;

yourName = name_txt.text;

yourSystem = system_txt.text;

yourHeight = height_txt.text;

blue_btn.addEventListener(MouseEvent.CLICK, onClick);

function onClick(event:MouseEvent):void {

 

addChild(body_txt);

body_txt.text= ""+ yourName +"'s ideal weight will be"

}"

I was thinking about starting with an "if statement" but I think there can be many other possibilities.

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
November 3, 2013

Start with gaining an understanding of the elements involved. especially the equations.  You do not want to assign, process, or calculate anything until after the button is clicked.

Is this a school assignment?

November 4, 2013

It is indeed a school assignment. 50% of the assignments I complete are half-finished, however, due to lack of application and knowledge in this type of subject I suppose. I can only work with Layman's terms, as sad as it is.

November 6, 2013

There is one more question I would like to ask: How do you divide?

Metric:Weight (kg) = height (metres) × height (metres) ÷ 25

Imperial: Weight (pounds) = height (inches) × height (inches) ÷ 25 ÷ 703

I am trying to use those two formulas to find the Metric and Imperial values, and here is what I have so far:

var yourMetric:Number;

var yourImperial:Number;

yourMetric = height_txt.text * height_txt.text/25;

yourImperial = height_txt.text * height_txt.text/25/703;

I get 5 errors saying "Implicit coercion to a type of value", etc. Using "String" gets me even more errors, so I use "Number" instead. What am I doing wrong? Is the divide sign that I am using wrong?

"/"