-2
var BMIValue = (WeightTextField*703)/(HeightTextField*HeightTextField)

My error:

Cannot invoke '/' with an argument list of type '(($T5), ($T11))'

I had made an attempt on making a simple BMI calculator however this function that I have typed out constantly brings compiler errors. Can someone please help me. Thank you very much.

Dharmesh Kheni
  • 71,228
  • 33
  • 160
  • 165
roshan
  • 1
  • 1
  • what are those: `WeightTextField` and `HeightTextField`? – holex Nov 11 '14 at 10:41
  • those are the user input for height and weight – roshan Nov 11 '14 at 10:42
  • You need to convert text to number – Sverrisson Nov 11 '14 at 10:43
  • @roshan, are those `UITextField` instances? – holex Nov 11 '14 at 10:44
  • thanks , i have one last question , must I assign the input provided as WeightTextField.text or just plain WeightTextField – roshan Nov 11 '14 at 10:47
  • @holex , yes they are – roshan Nov 11 '14 at 10:48
  • @roshan, is it not yet suspicious multiplying and dividing `UITextField` instances to you...? you have to convert their `text` value to number for doing arithmetical operands... – holex Nov 11 '14 at 10:50
  • @holex , i don't really understand , could you explain in a bit more simpler terms to me. I'm new to this. Thanks – roshan Nov 11 '14 at 10:52
  • @roshan, if you are newbie, first you need to read more about `UITextField`, here: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextField_Class/index.html and converting string to number, e.g. here: http://stackoverflow.com/questions/24085665/convert-string-to-float-in-apples-swift – holex Nov 11 '14 at 10:53
  • @holex , i tried doing what is shown in the answer but i get a new problem , the code breaks at abc.toInt()! – roshan Nov 11 '14 at 11:23
  • Do you know what to do in this case , also , while running the app in the simulator , the app freezes after i click the button – roshan Nov 11 '14 at 11:24

1 Answers1

0

This solution , converts UITextfields text into Floats and then assign BMI value to another float variable.

var weight = (WeightlTextField.text as NSString).floatValue
var height = (HeightTextField.text as NSString).floatValue
var BMIValue = (weight*703)/height

Hope this helps .

cromanelli
  • 576
  • 1
  • 5
  • 21