![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Oct 2005
Posts: 8
Rep Power: 0
![]() |
need some help please
im very new to this, just started it in computing class and im just wondering if anyone could help me. i am trying to make a BMI calculator. i have the formula for it but i run into problems with the last line of the code when trying to turn it from a real to string for putting it into the third text box after using the calculate button and i am not sure how to do so. everything i have tried doesnt work. thanks
|
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Apr 2005
Posts: 218
Rep Power: 4
![]() |
What code do you already have, Show some and it will be alot easier for people to help out instead of imagining the code in-front of us
|
|
|
|
|
|
#3 |
|
Programming Guru
![]() ![]() ![]() |
may need to convert data type... code?
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Oct 2005
Posts: 8
Rep Power: 0
![]() |
procedure TForm1.Button1Click(Sender: TObject); var weight:integer; var height:integer; var height2:real; var bmi:real; begin weight := strtoint(edit1.text); height := strtoint(edit2.text); height2 := height / 100; bmi := weight / (height2 * height2); bmi := not sure what to do here to put it into edit3.text end; sorry about this. i know i probably got it all wrong but keep in mind i am very very very new to this and rushed this so could you point out what im doing wrong. thanks alot. |
|
|
|
|
|
#5 |
|
Programming Guru
![]() ![]() ![]() |
I don't know Delphi but how about:
edit3.text = inttostr(bmi); where the inttostr function would be one in which it converts the numeric type of bmi into a string and assigned to the text property of the edit3 textbox.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#6 |
|
Newbie
Join Date: Oct 2005
Posts: 8
Rep Power: 0
![]() |
thanks for the help. but i get an error when compiling saying "there is no overloaded version of 'IntToStr' that can be called with these arguments". any idea what else i could try?
|
|
|
|
|
|
#7 |
|
Programming Guru
![]() ![]() ![]() |
Check for a function that can convert 'real' datatypes to strings. The inttostr function is expecting an int and the bmi variable is a real... so it blows up. Get the 'real' equivalent of this converting function and replace the function name in the code above. I don't know what this function name would be as I do not use Delphi.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#8 |
|
Newbie
Join Date: Oct 2005
Posts: 8
Rep Power: 0
![]() |
its working now. i looked it up and it was floattostr function. thanks alot for all the help. now all i need is to get it to round to 1 decimal place. how can i get it to do that? thanks again for the help
|
|
|
|
|
|
#9 |
|
Programming Guru
![]() ![]() ![]() |
glad it worked out for you...
For your rounding problem, just looking at google briefly, gave me this: http://www.latiumsoftware.com/en/delphi/00033.php function RoundD(x: Extended; d: Integer): Extended; // RoundD(123.456, 0) = 123.00 // RoundD(123.456, 2) = 123.46 // RoundD(123456, -3) = 123000 var n: Extended; begin n := IntPower(10, d); x := x * n; Result := (Int(x) + Int(Frac(x) * 2)) / n; end;
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#10 |
|
Newbie
Join Date: Oct 2005
Posts: 8
Rep Power: 0
![]() |
thanks i got that sorted now too. i have one last little problem though. i can get it to show a message when the value of bmi is above or below a certain value, but im not sure how to set it inbetween two values like if >18.5<30 on delphi. how do i do this?
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|