Languages :: Pascal :: FIRST PASCAL ASSIGNMENT NEED SOME HELP!!! |
|||
| By: collegeBoy |
Date: 31/12/2002 00:00:00 |
Points: 60 | Status: Answered Quality : Excellent |
|
MY FIRST ASSIGNMENT IS TO WRITE A PROGRAM WHICH GIVES THE USER A QUOTATION FOR AN INSURANCE POLICY INPUT FOR PROGRAM: NAME VALUE OF CAR BELOW ARE THE THREE CRITERIA'S 1)AGE 2)IF IT'S A BRITISH CAR 3)CLEAN LICENCE FOR LAST 3 YEARS IF ALL CRITERIA ARE TRUE THEN THERE WOULD BE A CALCULATION MADE FOR THE FINAL PAYMENT IF 1 AND 2 WERE TRUE AND 3 WAS FALSE THERE WOULD BE ANOTHER CALCULATION FOR THAT PAYMENT AND SO ON IF NONE ARE TRUE THEN POLICY REFUSED THE PROGRAM IS BELOW PLEASE HELP ME!!! I NEED TO KNOW WHAT I AM DOING WRONG var age,value:real; car,licence:char ; name:string[20]; Begin gotoxy(20,1); gotoxy(20,3); gotoxy(5,6); write('How old are you : '); readln(age); gotoxy(5,7); write('Do you have a British car?(Y/N): '); read(car); gotoxy(5,8); write('do you have a clean driving licence for 3 years?'); readln(licence); gotoxy(5,9); write('What is Your Name :'); readln(name); gotoxy(5,10); write('Please Enter the value of your car : £'); readln(value); gotoxy(24,12); writeLN('Name : ',name ); GOTOXY(24,13); write('Value of Vehcile : £',value:5:2); GOTOXY(9,20); if (age>=25) and (licence='n') and (car='n') then writeln('you have ',value/((100)*7)+(200):4:2); if (licence='y') and (car='n') and (age<25)then writeln('you have ',value/((100)*9)+(150):4:2); if (licence='y') and (car='y')and (age<25) then writeln('you have',value/((100)*7)+(100):4:2); if (age>=25) and (car='y') and (licence='n')then writeln('you have',value/((100)*8)+(100):4:2); if (age>=25) and (licence='y') and (car='y') then writeln('you have',value/((100)*6)+(0):4:2) else writeln('POLICY REFUSED'); end. |
|||
| By: TheFalklands | Date: 31/12/2002 02:12:00 | Type : Comment |
|
| the assignment is quite easy set up a record and just use if statements... dont use the goto rule it makes the program so much more complicated. use procedures to get user info and then another procedure to do the calculations and then another to dispaly all the results to the screen...pseudo code for such a program would be procedure get user info |
|||
| By: sumotimor | Date: 31/12/2002 05:46:00 | Type : Comment |
|
| Since you did not tell us what the problem is that you have observed, we have to guess. The program almost always shows "POLICY REFUSED" - except where the inputs are (age >=25), licence = y and car = y, when it produces a correct response? Or does it not even get that far? Does it stop? If so, where does it stop? Consider VERY CAREFULLY what the following from your program will do: if (age>=25) and (licence='y') and (car='y') then writeln('you have',value/((100)*6)+(0):4:2) else writeln('POLICY REFUSED'); and will this have a bearing on the displays from other possibilities? Further, are you sure that your inputs are in the correct case? 'Y' <> 'y', remember! Hope this gives you a few clues... (btw...the first 2 GOTOXYs are redundant; and you appear to use both READ and READLN to accept a flag value; you have no code to force the user to input Y or N (what happens if the user types "Q" for instance?) ... but these are all improvements not directly affecting the operation of your code) And PLEASE, don't post in ALL-UPPERCASE. It's very hard to read, especially at this time of year :) Many people interpret all-uppercase as SHOUTING. Good Luck |
|||
| By: collegeBoy | Date: 01/01/2003 00:48:00 | Type : Comment |
|
| thanks i sorted most of it out but i'm still getting no out put display at all. and rholding thanks about procedures.i have been looking for info on it but can't find any could you help? and how long would it take to get this program done with procedures? thanks for you help in advance Happy New Year Too All |
|||
| By: monange | Date: 01/01/2003 05:21:00 | Type : Comment |
|
| No advantage in this program in using procedures. Procedures would make it look tidy but that's about all. If you are getting no output display then sprinkle lots of Writeln statements into your code eg. if (age>=25) and (licence='n') and (car='n') then writeln('you have ',value/((100)*7)+(200):4:2); Writeln('If statement Number 1'); if (licence='y') and (car='n') and (age<25)then writeln('you have ',value/((100)*9)+(150):4:2); Writeln('If statement Number 2); if (licence='y') and (car='y')and (age<25) then writeln('you have',value/((100)*7)+(100):4:2); These will show you what bits of code are executing and what is not. If you get If statement Number 1 If statement Number 2 then you know that the if statement between the two didn't produce a result. |
|||
| By: VGR | Date: 05/01/2003 21:04:00 | Type : Assist |
|
| my humble rewriting of your program : Program InsuranceQuote(InPut,OutPut); var age, value : real; // beware, this is platform-dependent, use other float types car, licence : char ; name : string[20]; ok : Boolean; Begin ClearScreen; GotoXY(5,6); write('How old are you : '); readln(age); // real, so IO error if not a float entered (like a character) - beware, use string input and then conversion code having error-recovery looping gotoxy(5,7); write('Do you have a British car?(Y/N): '); read(car); // char gotoxy(5,8); write('do you have a clean driving licence for 3 years?'); readln(licence); // char gotoxy(5,9); write('What is Your Name :'); readln(name); // string[20] gotoxy(5,10); write('Please Enter the value of your car : £'); readln(value); // real, same remark as for "age" input // now output gotoxy(24,12); writeLN('Name : ',name ); GOTOXY(24,13); write('Value of Vehcile : £',value:5:2); GOTOXY(9,20); // BEWARE, given your logic, policy is refused if : car='y' and age<25 ; if age<25 and (lic='n' OR car='y') ; // minimizing the number of tests ok:=False; // default value If age>=25 Then Begin // useless but cleaner and more maintanable If licence='n' Then if car='n' Then Begin val1:=7; val2:=200; End Else Begin val1:=8; val2:=100; End; Else // licence='y' if car='y' then Begin val1:=6; val2:=0; End // else (car='n' and licence='y') nothing done, beware, policy will be refused! End // if age>=25 else Begin // age<25 If licence='y' Then If car='n' then Begin val1:=9; val2:=150; End Else Begin val1:=7; val2:=100; End // else (licence='n') nothing done, beware, policy will be refused! End; // if age<25 // now printout result of your logic if ok then writeln('you have',(value/(100.0*val1)+val2):4:2) else writeln('POLICY REFUSED'); // finished end. // InsuranceQuote Program PS : parentheses around logical/boolean tests are generally useless, especially if you master the precedence of operators ;-) |
|||
| By: VGR | Date: 05/01/2003 21:05:00 | Type : Comment |
|
| add declaration of Var val1, val2 : Integer; // or Word |
|||
| By: sumotimor | Date: 05/01/2003 21:11:00 | Type : Comment |
|
| "No output display at all"? Do you mean that you've got no results display, or that you're not even getting the prompt to input your data? Oh - and "Criteria's"? Aren't they even teaching the English English any more? (Criteria is already a plural - and you don't normally add an apostrophe before a terminal "s" to form a plural) ... |
|||
| By: VGR | Date: 05/01/2003 21:22:00 | Type : Comment |
|
| yes and no for criterium/criteria Correct English is to use the first word to enter English from Latin and build new English desinences (like a plural) upon it. It's the same in French with Latin words, like "media" (in "mass media"). In the singular, it ***should*** be "medium", but who uses it ? ;-) On the contrary, ***if and only if*** you clearly state (italicize, quote, etc) that the word you are using IS FOREIGN, then you use the foreign rule for plural versus singular, like in "medium/media" or "criterion/criteria" (or "criterium") |
|||
| By: sumotimor | Date: 06/01/2003 23:58:00 | Type : Comment |
|
| VGR: The singular is criterion - it's GREEK, not LATIN. You use it for clarity. I'd be intrigued to know how you demonstrate this quoting or itilicisation in speech. I'd also suggest thatsince even teachers now teach what is politically correct, easier or least likely to cause controversery than what is correct (if they know in the first place), then attempting to have the public indicate foreign words and phrases in the manner you advocate is beyond the realms of possibility. I mean, Uncle Bill has single-handedly persuaded the word to not indent paragraphs - all for the sake of his own convenience :) ... |
|||
| By: VGR | Date: 07/01/2003 00:10:00 | Type : Comment |
|
| sorry, but criterium is Latin, from the Greek meaning "to judge" ;-) I will comment <B>in bold</B> the Littré for you : CRITERIUM (kri-tè-ri-om'), s. m. Terme de philosophie. Marque qui fait discerner, juger. Le criterium de la vérité. Dans cette foule de sentiments, quel sera notre criterium pour en bien juger ? J. J. ROUSS. Sciences, II. Au plur. Des criteriums. <B>a criterium, plural "criteriums"</B> REMARQUE : Quelques auteurs ont francisé ce mot et dit critère. Il est clair que l'étude des sciences et de l'organisation sociale est le véritable critère expérimental pour juger si une idée a ou n'a pas l'importance qu'y attache dans ses réflexions solitaires l'auteur d'une table de catégories, COURNOT, Traité de l'enchaînement des idées, cité dans Revue de l'instr. publique, 26 déc. 1861, p. 811. <B>remark : some authors have francized this word, hence the word "critère"</B> ÉTYMOLOGIE : Lat. criterium, le terme grec vient du verbe juger (voy. CRISE). <B>explicit</B> An English/French official dictionnary for terminology (<A HREF="http://www.granddictionnaire.com/_fs_global_01.htm">http://www.granddictionnaire.com/_fs_global_01.htm</a>) gives this out for English : criterion s.m. : synonym of criterium n. m. And as criterium is Latin, from the Greek, sorry for you 8-)) |
|||
| By: VGR | Date: 07/01/2003 01:00:00 | Type : Comment |
|
| While speaking, you may render the "quoting" by stopping a while before the foreign word ; everybody understands that you are using a foreign word. You may also say "I'm quoting" before effectively quoting someone or something. |
|||
| By: collegeBoy | Date: 07/01/2003 06:31:00 | Type : Comment |
|
| hey thanks for your help i just got some other problem (licence='Y' or licence='y') i don't know wats going on here could some one please help and also when the user enters a answer for the questions is there away where if they type something other then y/n or Y/N that the program will just erase it there and then |
|||
| By: sumotimor | Date: 07/01/2003 14:47:00 | Type : Answer |
|
| (licence='Y' or licence='y') will yield a syntax error, because the parser cannot distinguish between what you want ((licence='Y') or (licence='y')) ie., Boolean or Boolean and what you have written (licence = 'Y' or licence = 'y') variable = char or variable = char it's objecting to the '= char or variable' part, as it's attempting to logically OR the char (which isn't a Boolean) with the variable contents (also not Boolean). Simply put the Boolean expressions in parentheses (as demonstrated) OR try if upcase(licence) = 'Y' then... OR, try a CASE statement case licence of 'Y','y' : begin .... end; 'N','n' : begin .... end; else begin ... end; end; OR a repeat to solve: repeat gotoxy(5,8); write('do you have a clean driving licence for 3 years?'); readln(licence); licence := upcase(licence); until licence in ['N','Y']; which will ... well, repeat the prompt until either 'N' or 'Y' in either case is input, then convert the character to upper-case, making the comparison job easier later on. ... |
|||
| By: VGR | Date: 08/01/2003 07:05:00 | Type : Comment |
|
| yes. You thus introduce some "security" to your user-inputs, which is good practice ;-) please remark that the "(licence='Y' or licence='y')" assertion is NOT in my code, and that the latter strictly reproduces your wished behaviour. I even made clearly apparent (in comments) the cases where no action is taken, thus explaining perhaps somehow why sometimes your logic produces "POLICY REFUSED" |
|||
|
Do register to be able to answer |
|||
| Add This Article To: | |||
| |
|
|
|
| |
|
|
|








