Forum > Beginners

Condicional Statement for Real Numbers

(1/1)

IAmTheLaw:
Hey, i need help with this, i made a program which calculates the value of (Y) depending on the value of the independent variable(x), the problem is that depending on the value of x the (Y) function is diferrent. To solve that i use a 'if .. then' statement, but when i try to run it it shows an error message - error: operation "and" not supported for types "real" and "real" - and i have no clue how to solve it, as i have understood i can not use the 'case' statement because it only works with integers. So what else can i do?

This is what i've got:

begin
  if 298.15<x and x<873.15 then
    Y:=0.49*x+294.16
  else if 873.15<x and x<1008.15 then
    Y:=(0.0003*x**3)-(0.7589*x**2)+(679.57*x)-202627
  else if 1008.15<x and x<1173.15 then
    Y:=(0.0617*x**2)-(138.05*x)+77914
  else
    Y:=650;
end.           

taazz:

--- Code: ---begin
  if (298.15<x) and (x<873.15) then
    Y:=0.49*x+294.16
  else if (873.15<x) and (x<1008.15) then
    Y:=(0.0003*x**3)-(0.7589*x**2)+(679.57*x)-202627
  else if (1008.15<x) and (x<1173.15) then
    Y:=(0.0617*x**2)-(138.05*x)+77914
  else
    Y:=650;
end.           

--- End code ---

"and" is both a boolean and bitwise operator using parenthesis you instruct the compiler to use the boolean and operator instead of the bitwise one.

Blaazen:
Hi,
Useful table: http://www.freepascal.org/docs-html/ref/refch12.html

Navigation

[0] Message Index

Go to full version