Question Simple Problem - Beginners code

soapface

New member
Joined
Jun 3, 2013
Messages
2
Programming Experience
Beginner
I'm currently doing a school assignment. The aim is to basically find out the amount of animals there are remaining when a certain percentage is wiped out, you then enter the amount of years that the species of animal is declining.
I have 3 textboxes, a calculate button and a label to display my answer.

I'm not 100% what equation to use.
My equation
1000 * (1 - 0.50) ^ 2
1000 animals, they are reducing 50% every year for two years.

The code:

VB.NET:
[COLOR=#333333]Code:
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Dim animals, rate, year as Integer
animals = txtAnimals.Text
rate = txtRate.Text
year = txtYear.Text
lblDisplayNum.Text = animals * (1 - rate) ^ year
  End Sub[/COLOR]

It doesn't seem to work, I put 1000, 0.5 and 2 into the textbox fields and press calculate, my answer is 1000. It's stuffed up.
I tried again and put 1000, 10 and 2 and it came up with 81000 as the answer.
 
I replied to the thread ages ago, it just needs to wait for a moderator to accept and I did admire his help.
I think I did solve it just by declaring the 'rate' as a double due to using a decimal place number.
 
Back
Top