Forum > Beginners

If Then else Question

(1/1)

Unkownuser002:
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:
Here you assign the integer number 20 to a variable

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- RVersandpauschale:=20
then you assign a string value to the same variable

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- 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:
Try this

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  //Eingabe           RBestellBetrag:=strtofloat(EBestellBetrag.text);  //Rechnen                        if RBestellBetrag<200 then                RVersandpauschale:=20             else            Begin                RVersandpauschale:=0;                RRabatt:=4;           end;           RGesamt:=(RBestellBetrag+RVersandpauschale)*0.96;  //Ausgabe           EGesamt.text:=floattostr(RGesamt