Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 11th, 2005, 2:16 PM   #1
bison
Newbie
 
Join Date: Oct 2005
Posts: 8
Rep Power: 0 bison is on a distinguished road
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
bison is offline   Reply With Quote
Old Oct 11th, 2005, 2:21 PM   #2
zorin
Hobbyist Programmer
 
Join Date: Apr 2005
Posts: 218
Rep Power: 4 zorin is on a distinguished road
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
zorin is offline   Reply With Quote
Old Oct 11th, 2005, 2:53 PM   #3
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Old Oct 11th, 2005, 3:21 PM   #4
bison
Newbie
 
Join Date: Oct 2005
Posts: 8
Rep Power: 0 bison is on a distinguished road
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.
bison is offline   Reply With Quote
Old Oct 11th, 2005, 3:25 PM   #5
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Old Oct 11th, 2005, 4:06 PM   #6
bison
Newbie
 
Join Date: Oct 2005
Posts: 8
Rep Power: 0 bison is on a distinguished road
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?
bison is offline   Reply With Quote
Old Oct 11th, 2005, 4:31 PM   #7
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Old Oct 11th, 2005, 5:02 PM   #8
bison
Newbie
 
Join Date: Oct 2005
Posts: 8
Rep Power: 0 bison is on a distinguished road
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
bison is offline   Reply With Quote
Old Oct 12th, 2005, 8:17 AM   #9
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Old Oct 12th, 2005, 2:26 PM   #10
bison
Newbie
 
Join Date: Oct 2005
Posts: 8
Rep Power: 0 bison is on a distinguished road
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?
bison is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:12 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC