Recent

Author Topic: If Then else Question  (Read 2839 times)

Unkownuser002

  • Newbie
  • Posts: 1
If Then else Question
« on: November 23, 2021, 09:24:13 pm »
Hey, New here and I got a quick question

I'm trying to figure out the if then else case. I get the error message:
unit1.pas(50,36) Error: Incompatible types: got "Constant String" expected "Real"
unit1.pas(57,4) Fatal: Syntax error, ";" expected but "." found

Sorry if this is relay easy but like I said I'm new and trying to figure this out

So what I'm trying to do is when the amount that is entered in the top is above 200, it will give you a discount of 4% and the extras shipping cost will be clear, but if it's above 200 then there will be a 20 dollar shipping fee.

Sorry for it being in German..


//Eingabe
           RBestellBetrag:=strtofloat(EBestellBetrag.text);
  //Rechnen
           begin
             if RBestellBetrag<200 then
                RVersandpauschale:=20
             else
                RVersandpauschale:='';
                RRabatt:=4;
           end;
           RGesamt:=(RBestellBetrag+RVersandpauschale)*0.96;
  //Ausgabe
           EGesamt.text:=floattostr(RGesamt);       

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: If Then else Question
« Reply #1 on: November 23, 2021, 09:29:42 pm »
Here you assign the integer number 20 to a variable

Code: Pascal  [Select][+][-]
  1.  RVersandpauschale:=20

then you assign a string value to the same variable

Code: Pascal  [Select][+][-]
  1.  RVersandpauschale:=''

As you don't show types, it is hard to guess which type (string or numeric) is right. But there is definitely a typing logic failure there

Paolo

  • Sr. Member
  • ****
  • Posts: 499
Re: If Then else Question
« Reply #2 on: November 23, 2021, 09:31:17 pm »
Try this
Code: Pascal  [Select][+][-]
  1.  
  2.  
  3. //Eingabe
  4.            RBestellBetrag:=strtofloat(EBestellBetrag.text);
  5.   //Rechnen
  6.            
  7.              if RBestellBetrag<200 then
  8.                 RVersandpauschale:=20
  9.              else
  10.             Begin
  11.                 RVersandpauschale:=0;
  12.                 RRabatt:=4;
  13.            end;
  14.            RGesamt:=(RBestellBetrag+RVersandpauschale)*0.96;
  15.   //Ausgabe
  16.            EGesamt.text:=floattostr(RGesamt
  17.  

 

TinyPortal © 2005-2018