I have to calculate commissions for different interval of sales on different days and form a table "Day", "Sales", "Commissions". So far I've done this:
real::a(5),b(5)
character(10)::c(5)=(/Sunday,Monday,Tuesday,Wednesday,Thursday/)
open(1,file='in_1.txt')
open(2,file='out_1.txt')
read(1,*)(a(i),i=1,5)
do i=1,5
if(0.<a(i).and.a(i)<99.)then
b(i)=a(i)*.02
elseif(100.<a(i).and.a(i)<299.)then
b(i)=a(i)*.05
elseif(300.<a(i).and.a(i)<499.)then
b(i)=a(i)*.075
else
b(i)=500.*.1+(a(i)-500.)*.125
endif
enddo
write(2,*)' Day ',' Sales ',' Commissions '
do i=1,5
write(2,10)c(i),a(i),b(i)
10 format(a10,t15,f4.1,t25,f8.2)
enddo
total=0.
do i=1,5
total=total+b(i)
enddo
write(2,20)total
20 format('Total Commissions',t25,f8.2)
end
The sales from sunday to thursday are in the input file in_1.txt.
When run, it shows the error: Element in REAL(4) array constructor is INTEGER(4).
What does it mean and how to resolve it?
implicit noneas your first line will show you why there is a problemSundayis not"Sunday". Mentioning that if character literals are meant, the array constructor isn't valid, for which a duplicate can be found. So: I think clarification is required as to what the problem is.thursdayis a variable,"thursday"is a character literal. The variablethursdayhas not been defined yet, that is what the compiler is complaining about.