首页 > 解决方案 > 逻辑运算符 '.or.' 的操作数 在(!)是逻辑(4)/字符(1)

问题描述

我有以下代码:

print*,"type s for a square and type t for a triangle"
read*,fig
if(fig =='t' .or. 'T') then
print*,"Enter the sides of the triangle"
read*,a,b,c
area=tri(a,b,c)
print*,"The area of the triangle is",area
else if (fig=='s' .or.'S') then 
print*,"Enter the side of the square"
read*,s
area=sq(s)

它给了我以下错误:

intro_fun.f:9:24:

  if(fig == 't' .or. 'T') then
                        1
Error: Operands of logical operator '.or.' at (1) are LOGICAL(4)/CHARACTER(1)
intro_fun.f:14:27:

  else if(fig=='s' .or. 'S') then
                           1
Error: Operands of logical operator '.or.' at (1) are LOGICAL(4)/CHARACTER(1)

标签: fortrangfortran

解决方案


您正在使用以下语句:

if(fig == 't' .or. 'T') 这应该是:

if(fig == 't' .or. fig == 'T')


推荐阅读