I have attached my source code. I am currently working on a program that will take data from a text array file and calculate the total average mpg,the standard deviation, the yearly mpg and the average mpg by season(Summer and Winter). When I try to calculate the mpg per season, my code does not cooperate. I am having two problems, the first is that I was earlier getting a result of 0 and now after changing my code I get an error that tells me that the "&" is an invalid token but I am merely using it to continue the line. Any help would be appreciated.
Program Fuel Consumption
Implicit none
Real Gal(290),MPG(290),TotalGal,Variance,StdDev,Totalsummer
Real MPGAvg,MPG93,MPG94,MPG95,MPG96,MPG97,MPG98,Totalwinter,TotalMonths
Real Summer, Winter
Integer Yr(290),Mon(290),Day(290),Mi(290),h,k,l,m,n,p,q,s,t,u,y
Integer z,OtherMonths
Winter=0
Summer=0
Totalsummer=0
Totalwinter=0
Open (unit=2, file = "car.dat")
! This format reads in the file breaking it into a five column array
10 Format(I4,I2,I2,1x,I5,1x,F4.1)
! This loop reads into the array
Do 100 k=1,290
Read (2,10) Yr(k),Mon(k),Day(k),Mi(k),Gal(k)
100 continue
Do 102 m=1,290
mpg(m)=(Mi(m)-Mi(m-1)/Gal(m))
TotalGal=Gal(m)+TotalGal
102 Continue
! This calculates the average mpg
MPGAvg=(Mi(290)-Mi(1))/TotalGal
Do 103 n=1,290
mpg=(Mi-Mi(n-1))/Gal
! This calculates the variance and standard deviation
Variance=Variance+((mpg-MPGAvg)**2)
103 continue
StdDev=(Variance/290)**.5
! The following calculates the average mpg per season
If(Mon(k).eq. 1 .or. Mon(k).eq. 2 .or. Mon(k) .eq. 11&
&.or. Mon(k).eq. 12) then
Winter=Winter+1
Totalwinter=Totalwinter+mpg
Else If (Mon(k).eq. 6 .or.Mon(k).eq. 7.or.Mon(k).eq. 8&
&.or.Mon(k).eq. 9)then
Summer=Summer+1
Totalsummer=Totalsummer+mpg(m)
Else
OtherMonths=OtherMonths+1
TotalMonths=TotalMonths+mpg(m)
End If
Totalwinter=Totalwinter/Winter
Totalsummer=TotalSummer/Summer
Write(6,*)"Total Winter is", Totalwinter
Write(6,*) "This is the average fuel consumption"
Write(6,*) MPGAvg
Write (6,*)"This is the sigma distribution"
Write(6,*)StdDev
! The following code will calculate the average mpg for each year
Do 104 p=2,63
Gal(p)=Gal(p)+Gal(p-1)
104 continue
MPG93=(Mi(p)-Mi(p-1))/Gal(p)
Write(6,*)"This is the average MPG for 1993"
Write(6,*)MPG93
Do 105 q=65,117
Gal(q)=Gal(q)+Gal(q-1)
105 continue
MPG94=(Mi(q)-Mi(q-1))/Gal(q)
Write(6,*)"This is the average MPG for 1994"
Write(6,*)MPG94
Do 106 s=119,188
Gal(s)=Gal(s)+Gal(s-1)
106 continue
MPG95=(Mi(s)-Mi(s-1))/Gal(s)
Write(6,*)"This is the average MPG for 1995"
Write(6,*)MPG95
Do 107 t=190,245
Gal(t)=Gal(t)+Gal(t-1)
107 continue
MPG96=(Mi(t)-Mi(t-1))/Gal(t)
Write(6,*)"This is the average MPG for 1996"
Write(6,*)MPG96
Do 108 u=247,284
Gal(u)=Gal(u)+Gal(u-1)
108 continue
MPG97=(Mi(u)-Mi(u-1))/Gal(u)
Write(6,*)"This is the average MPG for 1997"
Write(6,*)MPG97
Do 109 y=286,290
Gal=Gal+Gal(y-1)
109 continue
MPG98=(Mi(290)-Mi(285))/Gal(y-1)
Write(6,*)"This is the average MPG for 1998"
Write(6,*)MPG98
! The following prints values for the seasons
Write(6,*)"The average mpg during winter was"
Write(6,*) Totalwinter
Write(6,*)"The average mpg during summer was"
Write(6,*)Totalsummer
End
Program Fuel Consumption
Implicit none
Real Gal(290),MPG(290),TotalGal,Variance,StdDev,Totalsummer
Real MPGAvg,MPG93,MPG94,MPG95,MPG96,MPG97,MPG98,Totalwinter,TotalMonths
Real Summer, Winter
Integer Yr(290),Mon(290),Day(290),Mi(290),h,k,l,m,n,p,q,s,t,u,y
Integer z,OtherMonths
Winter=0
Summer=0
Totalsummer=0
Totalwinter=0
Open (unit=2, file = "car.dat")
! This format reads in the file breaking it into a five column array
10 Format(I4,I2,I2,1x,I5,1x,F4.1)
! This loop reads into the array
Do 100 k=1,290
Read (2,10) Yr(k),Mon(k),Day(k),Mi(k),Gal(k)
100 continue
Do 102 m=1,290
mpg(m)=(Mi(m)-Mi(m-1)/Gal(m))
TotalGal=Gal(m)+TotalGal
102 Continue
! This calculates the average mpg
MPGAvg=(Mi(290)-Mi(1))/TotalGal
Do 103 n=1,290
mpg=(Mi-Mi(n-1))/Gal
! This calculates the variance and standard deviation
Variance=Variance+((mpg-MPGAvg)**2)
103 continue
StdDev=(Variance/290)**.5
! The following calculates the average mpg per season
If(Mon(k).eq. 1 .or. Mon(k).eq. 2 .or. Mon(k) .eq. 11&
&.or. Mon(k).eq. 12) then
Winter=Winter+1
Totalwinter=Totalwinter+mpg
Else If (Mon(k).eq. 6 .or.Mon(k).eq. 7.or.Mon(k).eq. 8&
&.or.Mon(k).eq. 9)then
Summer=Summer+1
Totalsummer=Totalsummer+mpg(m)
Else
OtherMonths=OtherMonths+1
TotalMonths=TotalMonths+mpg(m)
End If
Totalwinter=Totalwinter/Winter
Totalsummer=TotalSummer/Summer
Write(6,*)"Total Winter is", Totalwinter
Write(6,*) "This is the average fuel consumption"
Write(6,*) MPGAvg
Write (6,*)"This is the sigma distribution"
Write(6,*)StdDev
! The following code will calculate the average mpg for each year
Do 104 p=2,63
Gal(p)=Gal(p)+Gal(p-1)
104 continue
MPG93=(Mi(p)-Mi(p-1))/Gal(p)
Write(6,*)"This is the average MPG for 1993"
Write(6,*)MPG93
Do 105 q=65,117
Gal(q)=Gal(q)+Gal(q-1)
105 continue
MPG94=(Mi(q)-Mi(q-1))/Gal(q)
Write(6,*)"This is the average MPG for 1994"
Write(6,*)MPG94
Do 106 s=119,188
Gal(s)=Gal(s)+Gal(s-1)
106 continue
MPG95=(Mi(s)-Mi(s-1))/Gal(s)
Write(6,*)"This is the average MPG for 1995"
Write(6,*)MPG95
Do 107 t=190,245
Gal(t)=Gal(t)+Gal(t-1)
107 continue
MPG96=(Mi(t)-Mi(t-1))/Gal(t)
Write(6,*)"This is the average MPG for 1996"
Write(6,*)MPG96
Do 108 u=247,284
Gal(u)=Gal(u)+Gal(u-1)
108 continue
MPG97=(Mi(u)-Mi(u-1))/Gal(u)
Write(6,*)"This is the average MPG for 1997"
Write(6,*)MPG97
Do 109 y=286,290
Gal=Gal+Gal(y-1)
109 continue
MPG98=(Mi(290)-Mi(285))/Gal(y-1)
Write(6,*)"This is the average MPG for 1998"
Write(6,*)MPG98
! The following prints values for the seasons
Write(6,*)"The average mpg during winter was"
Write(6,*) Totalwinter
Write(6,*)"The average mpg during summer was"
Write(6,*)Totalsummer
End