Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Help with Weight Calculator (Metric and Imperial)

Guest
Nov 03, 2013 Nov 03, 2013

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.

TOPICS
ActionScript
674
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 03, 2013 Nov 03, 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 03, 2013 Nov 03, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 05, 2013 Nov 05, 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?

"/"


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Nov 06, 2013 Nov 06, 2013
LATEST

I suppose

height_txt.text

is some kind of input textfield.

cast the string that you entered in a textfield as Number, to use it in a calculation.

yourMetric = Number(height_txt.text) * Number(height_txt.text)/25;

the divide signs are fine

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines