Hi i am trying to make a simple fraction calculator and im new to programming, i didnt quite understand all of what was on the internet and so far have this. but it dont work
here is the whole page of code its quite short and below iv highlighted the code that dont work.
the code that dont work is this which is suppose to take a fraction and reduce/simplify it
I cant work out why it dont work though.
here is the whole page of code its quite short and below iv highlighted the code that dont work.
Code:
<html>
<head>
<title></title>
</head>
<body>
<center>
<p>Fraction A...............................Fraction B................................Answer</p>
<input id="txtnum1" type="text" /><input id="txtnum2" type="text" /><input id="txtnum3" type="text" disabled="disabled" /></br>
<input id="txtden1" type="text" /><input id="txtden2" type="text" /><input id="txtden3" type="text" disabled="disabled" /></br>
<input id="btncalc" type="button" value="Calculate" /><input id="btnsimp" type="button" value="simplify" />
</center>
</body>
</html>
<script language="vbscript">
dim num as integer
dim den as integer
Dim GCD As Integer = GCF(num, den)
sub btncalc_onclick()
if txtden1.value = txtden2.value then
txtden3.value = (cint(txtden1.value) + cint(txtden2.value)) / 2
txtnum3.value = cint(txtnum1.value) + cint(txtnum2.value)
else
txtnum3.value = cint(txtnum1.value * txtden2.value) + cint(txtnum2.value * txtden1.value)
txtden3.value = txtden1.value * txtden2.value
end if
end sub
sub btnsimp_onclick()
num = txtnum3.value
den = txtden3.value
txtnum3.value = txtnum3.value / GCD
txtden3.value = txtden3.value / GCD
end sub
Private Function GCF(ByVal x As Integer, ByVal y As Integer) As Integer
x = Math.Abs(x)
y = math.Abs(y)
Dim z As Integer
Do
z = x Mod y
If z = 0 Then Return y
x = y
y = z
Loop
end function
</script>
the code that dont work is this which is suppose to take a fraction and reduce/simplify it
Code:
sub btnsimp_onclick()
num = txtnum3.value
den = txtden3.value
txtnum3.value = txtnum3.value / GCD
txtden3.value = txtden3.value / GCD
end sub
Private Function GCF(ByVal x As Integer, ByVal y As Integer) As Integer
x = Math.Abs(x)
y = math.Abs(y)
Dim z As Integer
Do
z = x Mod y
If z = 0 Then Return y
x = y
y = z
Loop
end function