Answer to Question #8745 in Visual Basic for wilfred
Caffeine absorption.after caffeine is absorbed into the body 13% is eliminated from the body each hour.assume a person drinks an 8 Oz cup of brewed coffee containing 130mg of caffeine,and the caffeine is absorbed immediately into the body.Write a program to compute the following values.the number of hours required until 65mg(one-half the orginal amount remain in the body.the amount of caffeine in the body 24hours after the person drinks the coffee
looking for the code
Just make the form in any VB version with 1 button, and add corresponding code.
The answer is 5 hours and 4mg.
Just in case, about 0,87: (X*100%-X*13%)/100%=x*87%/100%=X*0,87
So to remove 13% we just multiply by 0,87
Public Class Form1
Dim caff_dose As Integer 'to count current dose Dim hour As Integer 'to count hours Dim caff_half_dose_time As Integer 'to hold found 1 question value Dim hour24_left As Integer 'to hold found 2 question value
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'initial values caff_dose = 130 hour = 0
While caff_dose > 65 'the loop will end when the dose would fall below 65 hour = hour + 1 'increasing hours caff_dose = caff_dose * 0.87 'decreasing dose MsgBox("HALF DOSE TIME: on hour " & hour quot; we have " & caff_dose quot;mg") 'you can remove this line, just to show loop output caff_half_dose_time = hour 'so when the loop stops we will have desired number End While
'initial values again caff_dose = 130 hour = 0
While hour < 24 'the loop will end on 24-th hour hour = hour + 1 'same as above loop caff_dose = caff_dose * 0.87 'same as above loop MsgBox("24 HOURS: on hour " & hour quot; we have " & caff_dose quot;mg") 'you can remove this line, just to show loop output hour24_left = caff_dose 'so we have the second value End While
MsgBox("The number of hours required until 65mg amount remain in the body is " & caff_half_dose_time) MsgBox("The amount of caffeine in the body 24hours after the person drinks the coffee is " & hour24_left) End Sub End Class