![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Mar 2008
Posts: 3
Rep Power: 0
![]() |
problem
i am trying to find a way to get the power of something for my program but i cant sem to find anything can anyone help
e.g 4 to the power of 2 i need to know the coding to get the power of please help |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Sep 2007
Location: Sydney - Australia
Posts: 204
Rep Power: 2
![]() |
Re: problem
Look for something called a POW() function. You could hard code it like this (in BASIC psuedo):
DIM number_1 AS INTEGER = 4 DIM number_2 AS INTEGER = 2 DO UNTIL number == 0 number _2 -= 1 number_1 *= number_1 LOOP RETURN number_1
__________________
SYNTAX ERROR ... |
|
|
|
|
|
#3 |
|
Expert Programmer
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4
![]() |
Re: problem
vb.net Syntax (Toggle Plain Text)
|
|
|
|
|
|
#4 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Re: problem
OpenLoop's solution also works in VB Classic (VB 6 and below). Just use the
^ operator. |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Mar 2008
Posts: 3
Rep Power: 0
![]() |
Re: problem
i have tried using the ^ to no effect
the program i am using requires to find the bmi (body mass index) of a person with the formula BMI = weight in kilograms / height in metres^2 i have tried using this to no effect please help i also need ther code to put the answer to 1 decimal place thanks edit: here is the code that i have been using usersbmi(Counter) = usersweight(Counter) / usersheight(Counter) ^ 2 i think that it may be working but justs needs to be rounded to the decimal place e.g 24=24.3 Last edited by tyson642; Mar 17th, 2008 at 9:54 AM. |
|
|
|
|
|
#6 |
|
Newbie
Join Date: Mar 2008
Posts: 3
Rep Power: 0
![]() |
Re: problem
here is a copy of my program
Private Sub cmdok_Click()
Dim usersweight(5) As Integer
Dim usersheight(5) As Integer
Dim usersbmi(5) As Integer
Dim underweight As Integer
Dim idealweight As Integer
Dim overweight As Integer
underweight = 0
idealweight = 0
overweight = 0
Call get_inputs(usersweight(), usersheight())
Call calculate_bmi(usersbmi(), usersweight(), usersheight())
Call count_weight(usersbmi(), underweight, idealweight, overweight)
Call display_details(usersbmi(), usersweight(), usersheight(), underweight, idealweight, overweight)
End Sub
Private Sub get_inputs(ByRef usersweight() As Integer, ByRef usersheight() As Integer)
For Counter = 0 To 4
'validate users weight
Do
usersweight(Counter) = InputBox("please enter your weight")
If (usersweight(Counter) <= 0) Then MsgBox ("Sorry invalid weight, value must be greater then zero, please re-enter")
Loop Until (usersweight(Counter) > 0)
' validate users height
Do
usersheight(Counter) = InputBox("please enter your height")
If (usersheight(Counter) <= 0) Then MsgBox ("Sorry invalid height, value must be greater then zero, please re-enter")
Loop Until (usersheight(Counter) > 0)
Next
End Sub
Private Sub calculate_bmi(ByRef usersbmi() As Integer, usersweight() As Integer, usersheight() As Integer)
For Counter = 0 To 4
usersbmi(Counter) = usersweight(Counter) / usersheight(Counter) ^ 2
Next
End Sub
Private Sub count_weight(usersbmi() As Integer, ByRef underweight As Integer, ByRef idealweight As Integer, ByRef overweight As Integer)
For Counter = 0 To 4
If usersbmi(Counter) < 18.5 Then underweight = underweight + 1
If usersbmi(Counter) >= 18.5 And usersbmi(Counter) < 25 Then idealweight = idealweight + 1
If usersbmi(Counter) >= 25 Then overweight = overweight + 1
Next
End Sub
Private Sub display_details(usersbmi() As Integer, usersweight() As Integer, usersheight() As Integer, underweight As Integer, idealweight As Integer, overweight As Integer)
picdisplay.Print "weight"; Tab(25); "height"; Tab(50); "bmi"; Tab(75)
picdisplay.Print "---------------------"; Tab(25); "--------------------------"; Tab(50); "-------------------------"; Tab(75)
For Counter = 0 To 4
picdisplay.Print usersweight(Counter); Tab(25); usersheight(Counter); Tab(50); usersbmi(Counter); Tab(75)
Next
picdisplay.Print ""
picdisplay.Print "underweight"; Tab(25); underweight
picdisplay.Print "idealweight"; Tab(25); idealweight
picdisplay.Print "overweight"; Tab(25); overweight
End Subas you can see my main problem is the calculation Private Sub calculate_bmi(ByRef usersbmi() As Integer, usersweight() As Integer, usersheight() As Integer) For Counter = 0 To 4 usersbmi(Counter) = usersweight(Counter) / usersheight(Counter) ^ 2 Next End Sub |
|
|
|
|
|
#7 |
|
Expert Programmer
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4
![]() |
Re: problem
What does 'to no effect' mean? are you getting an incorrect answer? can you give a sample output with expected results?
If you want a decimal point, you should define your variables as Float not Integer (not sure what VB's type for float) Also, Try using parenthesis to isolate the calculation. VB Syntax (Toggle Plain Text)
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Challenging Programming Problem - "Pinball Ranking" | Sane | Coder's Corner Lounge | 38 | Jan 15th, 2008 5:16 PM |
| Problem solving | ReggaetonKing | Software Design and Algorithms | 7 | Jan 4th, 2008 1:49 PM |
| Storing BLOBs in a database - problem | jonyzz | Other Programming Languages | 8 | Jan 31st, 2007 4:38 AM |
| cgi/perl script + IE problem | joyceshee | Perl | 2 | Jan 24th, 2006 11:10 AM |
| help with recursion problem | the_new_guy_in_town | Java | 3 | Apr 7th, 2005 3:04 AM |