error: Arithmetic operation resulted in an overflow.
the error appears at the last place where fact is written
here is the code:
the error appears at the last place where fact is written
here is the code:
Code:
Module Module1
Sub Main()
'outline of program
Console.WriteLine("This program prompts the user to input a value for x radians in the function cos(x) and also a value n to specify the series amount please press any key to get started")
Console.ReadKey()
'ask for x and n as (integer)
Dim n As Integer
Dim x As Integer
Console.WriteLine("Please input an integer value for x")
Integer.TryParse(Console.ReadLine(), x)
Console.WriteLine("Please input an integer value for n")
Integer.TryParse(Console.ReadLine(), n)
'write the formula for cos(x)
Dim i As Integer = -1 ^ n
Dim numerator As Integer = x ^ 2 * n
'denominator
Dim fact, z As Long
n = Console.Read
fact = 1
For z = 2 To n
fact = fact * z
Next z
Console.Read()
Dim denominator As Integer
denominator = (2 * n) * fact
'output value for cos(x)
Dim answer As Integer = (i * numerator / denominator) / 57.295779513082323
Console.WriteLine(answer)
Console.ReadLine()
End Sub
End Module