Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Mar 13th, 2008, 5:27 AM   #1
tyson642
Newbie
 
Join Date: Mar 2008
Posts: 3
Rep Power: 0 tyson642 is on a distinguished road
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
tyson642 is offline   Reply With Quote
Old Mar 13th, 2008, 6:10 AM   #2
Grich
Hobbyist Programmer
 
Grich's Avatar
 
Join Date: Sep 2007
Location: Sydney - Australia
Posts: 166
Rep Power: 1 Grich is on a distinguished road
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 ...
Grich is offline   Reply With Quote
Old Mar 13th, 2008, 6:42 AM   #3
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
Re: problem

vb.net Syntax (Toggle Plain Text)
  1. DIM x AS INTEGER = 4
  2. DIM y AS INTEGER = 0
  3. y = x^3 'x to the power of 3, y = 64
OpenLoop is offline   Reply With Quote
Old Mar 14th, 2008, 8:46 PM   #4
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Re: problem

OpenLoop's solution also works in VB Classic (VB 6 and below). Just use the ^ operator.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Mar 17th, 2008, 9:40 AM   #5
tyson642
Newbie
 
Join Date: Mar 2008
Posts: 3
Rep Power: 0 tyson642 is on a distinguished road
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.
tyson642 is offline   Reply With Quote
Old Mar 17th, 2008, 10:22 AM   #6
tyson642
Newbie
 
Join Date: Mar 2008
Posts: 3
Rep Power: 0 tyson642 is on a distinguished road
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 Sub

as 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
tyson642 is offline   Reply With Quote
Old Mar 17th, 2008, 11:36 AM   #7
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
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)
  1. usersbmi(Counter) = (usersweight(Counter) / usersheight(Counter)) ^ 2
  2. or?
  3. usersbmi(Counter) = usersweight(Counter) / (usersheight(Counter) ^ 2)
OpenLoop 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

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




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

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