Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

Author Topic: Condicional Statement for Real Numbers  (Read 3975 times)

IAmTheLaw

• Newbie
• Posts: 4
Condicional Statement for Real Numbers
« on: May 23, 2014, 03:03:48 am »
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

• Hero Member
• Posts: 5368
Re: Condicional Statement for Real Numbers
« Reply #1 on: May 23, 2014, 04:04:00 am »
Code: [Select]
`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.            `
"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.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Blaazen

• Hero Member
• Posts: 3235
• POKE 54296,15
Re: Condicional Statement for Real Numbers
« Reply #2 on: May 23, 2014, 09:49:29 am »
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/