Ive tried several times To get this programme to work but it wont lazarus / 61-Beginners ---------------------------------------------------------------------- MyLAWLAWL · 2017-03-02 16:48 Program seen below continuously crashes when i get to the statement "net_income = (Monthly_income - Total_Expenses + Total_Monthly_Loan_Repayments);" can someone please tell me what im doing wrong and please note i am new to programming i just started yesterday so please don't be too harsh Program approved_applicants(input, output); uses crt; const      Clarendon_Court = 12500;      Sangre_Grande = 9500;      Providence_Gardens = 7500; var    housing_community, name : string;    net_income : real;    Monthly_Income : real;    Total_Monthly_Loan_Repayments : real;    Total_Expenses : real;   begin        writeln('Hello! Please choose your housing community Clarendon Court, Sangre Grande Villas, Providence Gardens:  ') ;        readln(housing_community);        writeln('Please enter your Full Name: ');        readln(name);        writeln('Please enter your Total Monthly Loan Repayments');        readln(Total_Monthly_Loan_Repayments);        writeln('Please enter your Total Monthly Expenses');        readln(Total_Expenses);        writeln('Please enter the your Monthly Income');        readln(Monthly_Income);        net_income = (Monthly_income - Total_Expenses + Total_Monthly_Loan_Repayments);                   If (housing_community='Providence Gardens')Then;                         If Net_income>=Sangre_Grande then                         If ((Total_Expenses + Total_Monthly_Loan_Repayments)>=net_income*0.5) then                         writeln('You have Successfully been approved for housing in Providence Gardens Congratulations')                      else                         writeln('Im truly sorry but you have been declined approval for housing in Providence Gardens')                   Else If (housing_community= 'Clarendon Court')Then                         If Net_income>=Clarendon_Court then                         If ((Total_Expenses + Total_Monthly_Loan_Repayments)>=net_income*0.5) then                            writeln('You have Successfully been approved for housing in Clarendon Court Congratulations')                         else                             writeln('Im truly sorry but you have been declined approval for housing in Claredon Court')                   Else If (housing_community='Sangre Grande Villas')Then                         If Net_income>=Providence_Gardens then                         If ((Total_Expenses + Total_Monthly_Loan_Repayments)>=net_income*0.5) then                            writeln('You have Successfully been approved for housing in Sangre Grande Congratulations')                        else                             writeln('Im truly sorry but you have been declined approval for housing in Sangre Grande'); end. ---------------------------------------------------------------------- JanRoza · 2017-03-02 16:52 In Pascal an assignment is written with := and not with just a =. So try this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i net_income := (Monthly_income - Total_Expenses + Total_Monthly_Loan_Repayments); ---------------------------------------------------------------------- molly · 2017-03-02 17:02 intended or not: Code: [Select]If (housing_community='Providence Gardens')Then; Note the use of the semi-colon at the end. btw: Quote from: MyLAWLAWL on March 02, 2017, 05:48:17 pmProgram seen below continuously crashes when i get to the statement "net_income = (Monthly_income - Total_Expenses + Total_Monthly_Loan_Repayments);"That is not crashing, that is called "the compiler stops compiling becuase it encountered an erro and informs you about this error" a crash is when you run your program and that program unexpectedly stops working with either a runtime error, sigv fault, or stops working completely without any notification ---------------------------------------------------------------------- Bart · 2017-03-02 17:07 Quote from: MyLAWLAWL on March 02, 2017, 05:48:17 pmProgram seen below continuously crashes when i get to the statement "net_income = (Monthly_income - Total_Expenses + Total_Monthly_Loan_Repayments);" How can the program crash if that line will not even compile? Bart ---------------------------------------------------------------------- jacmoe · 2017-03-02 17:09 Perhaps, what he calls 'crash', is the compiler failing to compile it? ---------------------------------------------------------------------- bee · 2017-03-03 03:21 The first thing you need to understand when learning a programming language is its syntax. Long before you start to apply logic into it. Syntax describes how to write a correct code in the particular language. So, I suggest you to read these first: - Free Pascal Language Reference: http://freepascal.org/docs- html/current/ref/ref.html - Pascal Language Tutorial: https://www.tutorialspoint.com/pascal/ - Object Pascal Tutorial: http://wiki.lazarus.freepascal.org/Object_Pascal_Tutorial Good luck! ---------------------------------------------------------------------- Thaddy · 2017-03-03 05:38 Apart from the two errors pointed to by JanRoza and molly the code compiles and works fine. Just the = and the then; must be := and then ---------------------------------------------------------------------- MyLAWLAWL · 2017-03-03 22:09 Quote from: bee on March 03, 2017, 04:21:19 amThe first thing you need to understand when learning a programming language is its syntax. Long before you start to apply logic into it. Syntax describes how to write a correct code in the particular language. So, I suggest you to read these first: - Free Pascal Language Reference: http://freepascal.org/docs- html/current/ref/ref.html - Pascal Language Tutorial: https://www.tutorialspoint.com/pascal/ - Object Pascal Tutorial: http://wiki.lazarus.freepascal.org/Object_Pascal_Tutorial Good luck! Thanks ---------------------------------------------------------------------- MyLAWLAWL · 2017-03-03 22:10 Quote from: JanRoza on March 02, 2017, 05:52:02 pmIn Pascal an assignment is written with := and not with just a =. So try this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i net_income := (Monthly_income - Total_Expenses + Total_Monthly_Loan_Repayments);   thanks lol i wouldnt have known sorry if i came across noobish ---------------------------------------------------------------------- MyLAWLAWL · 2017-03-03 22:11 Quote from: molly on March 02, 2017, 06:02:35 pmintended or not: Code: [Select]If (housing_community='Providence Gardens')Then; Note the use of the semi-colon at the end. btw: Quote from: MyLAWLAWL on March 02, 2017, 05:48:17 pmProgram seen below continuously crashes when i get to the statement "net_income = (Monthly_income - Total_Expenses + Total_Monthly_Loan_Repayments);"That is not crashing, that is called "the compiler stops compiling becuase it encountered an erro and informs you about this error" a crash is when you run your program and that program unexpectedly stops working with either a runtime error, sigv fault, or stops working completely without any notification oh okay sorry for sounding noobish ---------------------------------------------------------------------- MyLAWLAWL · 2017-03-03 22:26 I changed it but it crashes i full understand what crashing means now but it just cuts off at that point on my computer is there something wrong with it? i made the changes and it compiles successfully now Program approved_applicants(input, output); uses crt; const      Clarendon_Court = 12500;      Sangre_Grande = 9500;      Providence_Gardens = 7500; var    housing_community, name : string;    Monthly_Income : real;    Total_Monthly_Loan_Repayments : real;    Total_Expenses : real;    net_income : real;   begin        writeln('Hello! Please choose your housing community Clarendon Court, Sangre Grande Villas, Providence Gardens:  ') ;        readln(housing_community);        writeln('Please enter your Full Name: ');        readln(name);        writeln('Please enter your Total Monthly Loan Repayments');        readln(Total_Monthly_Loan_Repayments);        writeln('Please enter your Total Monthly Expenses');        readln(Total_Expenses);        writeln('Please enter the your Monthly Income');        readln(Monthly_Income);        net_income := (Monthly_income - Total_Expenses + Total_Monthly_Loan_Repayments);                   If (housing_community='Providence Gardens')Then                         If Net_income>=Sangre_Grande then                         If ((Total_Expenses + Total_Monthly_Loan_Repayments)>=net_income*0.5) then                         writeln('You have Successfully been approved for housing in Providence Gardens Congratulations')                      else                         writeln('Im truly sorry but you have been declined approval for housing in Providence Gardens')                   Else If (housing_community= 'Clarendon Court')Then                         If Net_income>=Clarendon_Court then                         If ((Total_Expenses + Total_Monthly_Loan_Repayments)>=net_income*0.5) then                            writeln('You have Successfully been approved for housing in Clarendon Court Congratulations')                         else                             writeln('Im truly sorry but you have been declined approval for housing in Claredon Court')                   Else If (housing_community='Sangre Grande Villas')Then                         If Net_income>=Providence_Gardens then                         If ((Total_Expenses + Total_Monthly_Loan_Repayments)>=net_income*0.5) then                            writeln('You have Successfully been approved for housing in Sangre Grande Congratulations')                        else                             writeln('Im truly sorry but you have been declined approval for housing in Sangre Grande'); end. ---------------------------------------------------------------------- Bart · 2017-03-03 22:49 Homework assignement I guess? It does not crash (as long as I give in correct input), but most of the times it does not output anything after I entered my Monthly Income. One time it did output something it declined me, even while my income was 50 thousand and my expenses ony 30... To make the code at the end more redable, put your if..then..else blocks inside begin..end blocks. Further: do not let the user enter the entire name of the project, especially when you later on compare the input in a case sensitive manner. Present the choice as something like: 1: project A 2: project B 3: project C And then let the user just enter 1,2, or 3. Since you use crt unit, you can use ReadKey function for that instead of Read or Readln. Validate input. In the example above do not accept anything but 1, 2 or 3. Why do you let me enter my name, and then don't use this later on anywhere? Bart ---------------------------------------------------------------------- marcov · 2017-03-03 23:07 This guy: http://stackoverflow.com/questions/42545156/why-am-i- getting-22-3-itprog1-pas-fatal-syntax-error-expected-but-else-fo seems to have a very similar problem. Hint: if you are not a master in when a ; before an ELSE is allowed and when not, add begin .. end pairs to your nesting. ---------------------------------------------------------------------- Bart · 2017-03-03 23:13 Try to follow your code when user selects; Providence Gardens Loan repayments: 10 Monthly expenses: 20 Monthly income: 200 You do want to end up in the 'Im truly sorry but you have been declined approval for housing in Providence Gardens', but the only if statement that evaluates to true is "If (housing_community='Providence Gardens')" all following if statements evaluate to False, and there will be no output at all. Code like Code: [Select]if a then if c then x else y else if q then if z then foo else bar is hard to read: which else belongs to which if? It may very well not be what you intended. OTOH Code: [Select]if a then begin   if b then     foo   else     bar end else if c then begin   if p then     foobar   else     barfoo end; is easier to follow and the compiler will do what you expect it to. Also: why do you approve me (in all cases) when my net income is less than my expenses? Bart ---------------------------------------------------------------------- jacmoe · 2017-03-03 23:14 @MyLAWLAWL : Could you Please edit your posts and surround your code with code tags ? As it is now, it is simply not pleasant to read at all. And that means that I don't bother taking the extra time required. And I suspect that not only applies to me, but a lot of other potential helpers. So, make it easy to help by making it easy to read.  My eye sight is not what it used to be, you know - and the time that I have is not what it used to be either. ---------------------------------------------------------------------- Bart · 2017-03-03 23:17 Code: [Select]  If (housing_community='Providence Gardens')Then   begin     If (Net_income>=Sangre_Grande) and This makes no sense at all. Why does somebody who is interested in 'Providence Gardens' have to have an income that seems to be reserved for 'Sangre Grande'? Bart ---------------------------------------------------------------------- Bart · 2017-03-03 23:35 This is how it could look: Code: [Select]C:\Users\Bart\LazarusProjecten\ConsoleProjecten\bugs\For um\Houses>test Hello! Please choose your housing community: 1: Clarendon Court 2: Sangre Grande Villas 3: Providence Gardens Enter your choice: 1 "Clarendon Court" Please enter your Full Name: Bart Please enter your Total Monthly Loan Repayments: 100 Please enter your Total Monthly Expenses: 200 Please enter the your Monthly Income: 12000 Bart: you have Successfully been approved for housing in Providence Gardens Congratulations Bart ---------------------------------------------------------------------- MyLAWLAWL · 2017-03-05 19:50 Quote from: jacmoe on March 04, 2017, 12:14:31 am@MyLAWLAWL : Could you Please edit your posts and surround your code with code tags ? As it is now, it is simply not pleasant to read at all. And that means that I don't bother taking the extra time required. And I suspect that not only applies to me, but a lot of other potential helpers. So, make it easy to help by making it easy to read.  My eye sight is not what it used to be, you know - and the time that I have is not what it used to be either. how do i do this ---------------------------------------------------------------------- MyLAWLAWL · 2017-03-05 19:51 Quote from: Bart on March 04, 2017, 12:17:10 amCode: [Select]  If (housing_community='Providence Gardens')Then   begin     If (Net_income>=Sangre_Grande) and This makes no sense at all. Why does somebody who is interested in 'Providence Gardens' have to have an income that seems to be reserved for 'Sangre Grande'? Bart my bad i will fix this error ---------------------------------------------------------------------- Bart · 2017-03-05 22:35 Quote from: MyLAWLAWL on March 05, 2017, 08:50:57 pmQuote from: jacmoe on March 04, 2017, 12:14:31 amCould you Please edit your posts and surround your code with code tags ? how do i do this When you type, ther is a buttonwith a "#" sign on it. Just press it, then type/paste your code between the tags. Alternatively type/paste the code, select it and then press the "#" button. Bart