hello, i am a new fortran user in college... our teacher is a first year teacher and has assigned us 3 programs to write, none of which she explained how to do. i read the entire book up to where we are but apparently i still do not grasp the full concept yet. we are supposed to write a program that calculates the value of Sin(x) with the infinite series (-1)**(n-1)*x**(2n-1)/factorial(2n-1)... i have written a program with 2 internal functions but i can not get it to compile without errors. here is the code
and here are my error messages:
In file infiniteSeries.f95:42
real, intent(in) :: x
1
Error: Unexpected data declaration statement at (1)
In file infiniteSeries.f95:43
integer, intent(in) :: n
1
Error: Unexpected data declaration statement at (1)
In file infiniteSeries.f95:44
integer :: i = 1
1
Error: Unexpected data declaration statement at (1)
In file infiniteSeries.f95:45
real :: fact
1
Error: Unexpected data declaration statement at (1)
In file infiniteSeries.f95:46
integer :: a = 2n - 1
1
Error: Syntax error in data declaration at (1)
In file infiniteSeries.f95:37
real function sinApprox(x,n)
1
Error: Symbol 'x' at (1) has no IMPLICIT type
In file infiniteSeries.f95:37
real function sinApprox(x,n)
1
Error: Symbol 'n' at (1) has no IMPLICIT type
In file infiniteSeries.f95:48
do i = 1, n
1
Error: Symbol 'i' at (1) has no IMPLICIT type
In file infiniteSeries.f95:49
sinApprox = sinApprox + (-1)**(n-1) * x**(2*n-1) / fact(a)
1
Error: Symbol 'a' at (1) has no IMPLICIT type
In file infiniteSeries.f95:49
sinApprox = sinApprox + (-1)**(n-1) * x**(2*n-1) / fact(a)
1
Error: Function 'fact' at (1) has no IMPLICIT type
In file infiniteSeries.f95:61
integer :: i = 1
1
Error: Unexpected data declaration statement at (1)
In file infiniteSeries.f95:63
do i = 1, a
1
Error: Symbol 'i' at (1) has no IMPLICIT type
if anyone could at least point me in the right direction as to where i am messing up, i would greatly appreciate it. thanks
Code:
program infiniteSeries
IMPLICIT NONE
real :: x = 0.
integer :: n = 1
real :: degRad = 3.1415926 / 180
real :: sinIntrinsic = 0., mySin = 0.
real :: sinApprox
write(*,*)"Please enter a value in degrees"
read(*,*)x
x = x * degRad
sinIntrinsic = sin(x)
do n = 1, 10
mySin = sinApprox(x,n)
write(*,*)n, mySin
end do
write(*,*)sinIntrinsic
end
real function sinApprox(x,n)
implicit none
sinApprox = 0.
real, intent(in) :: x
integer, intent(in) :: n
integer :: i = 1
real :: fact
integer :: a = 0
a = 2n - 1
do i = 1, n
sinApprox = sinApprox + (-1)**(n-1) * x**(2*n-1) / fact(a)
end do
end
real function fact(a)
implicit none
integer, intent(in) :: a
fact = 1.
integer :: i = 1
do i = 1, a
fact = fact * i
end do
end
and here are my error messages:
In file infiniteSeries.f95:42
real, intent(in) :: x
1
Error: Unexpected data declaration statement at (1)
In file infiniteSeries.f95:43
integer, intent(in) :: n
1
Error: Unexpected data declaration statement at (1)
In file infiniteSeries.f95:44
integer :: i = 1
1
Error: Unexpected data declaration statement at (1)
In file infiniteSeries.f95:45
real :: fact
1
Error: Unexpected data declaration statement at (1)
In file infiniteSeries.f95:46
integer :: a = 2n - 1
1
Error: Syntax error in data declaration at (1)
In file infiniteSeries.f95:37
real function sinApprox(x,n)
1
Error: Symbol 'x' at (1) has no IMPLICIT type
In file infiniteSeries.f95:37
real function sinApprox(x,n)
1
Error: Symbol 'n' at (1) has no IMPLICIT type
In file infiniteSeries.f95:48
do i = 1, n
1
Error: Symbol 'i' at (1) has no IMPLICIT type
In file infiniteSeries.f95:49
sinApprox = sinApprox + (-1)**(n-1) * x**(2*n-1) / fact(a)
1
Error: Symbol 'a' at (1) has no IMPLICIT type
In file infiniteSeries.f95:49
sinApprox = sinApprox + (-1)**(n-1) * x**(2*n-1) / fact(a)
1
Error: Function 'fact' at (1) has no IMPLICIT type
In file infiniteSeries.f95:61
integer :: i = 1
1
Error: Unexpected data declaration statement at (1)
In file infiniteSeries.f95:63
do i = 1, a
1
Error: Symbol 'i' at (1) has no IMPLICIT type
if anyone could at least point me in the right direction as to where i am messing up, i would greatly appreciate it. thanks