Greetings, programmers. There is a question, a task has been received: it is as easy as possible to integrate several laboratory works in a console application. How best to implement this? The kind of idea is this. The person writes the job number and it is executed. If it is possible, then with reference to the example.
1 answer
The easiest:
var num: integer; begin write("ΠΠ²Π΅Π΄ΠΈΡΠ΅ Π½ΠΎΠΌΠ΅Ρ Π·Π°Π΄Π°Π½ΠΈΡ: "); readln(num); if num=156 then begin {ΠΈΠ΄Π΅Ρ ΠΊΠΎΠ΄ Π·Π°Π΄Π°Π½ΠΈΡ 156} end; if num=223 then begin {ΠΈΠ΄Π΅Ρ ΠΊΠΎΠ΄ Π·Π°Π΄Π°Π½ΠΈΡ 223} end; if num=718 then begin {ΠΈΠ΄Π΅Ρ ΠΊΠΎΠ΄ Π·Π°Π΄Π°Π½ΠΈΡ 718} end; if num<>156 AND num<>223 AND num<>718 then begin writeln("Π’Π°ΠΊΠΎΠ³ΠΎ Π·Π°Π΄Π°Π½ΠΈΡ Π½Π΅Ρ."); readln(); end; end. A more complicated way is through procedures and functions. =)
UPD : Case will not save much =)
case num of '156' : begin {ΠΈΠ΄Π΅Ρ ΠΊΠΎΠ΄ Π·Π°Π΄Π°Π½ΠΈΡ 156} end; '223' : begin {ΠΈΠ΄Π΅Ρ ΠΊΠΎΠ΄ Π·Π°Π΄Π°Π½ΠΈΡ 223} end; '718' : begin {ΠΈΠ΄Π΅Ρ ΠΊΠΎΠ΄ Π·Π°Π΄Π°Π½ΠΈΡ 718} end; else begin writeln("Π’Π°ΠΊΠΎΠ³ΠΎ Π·Π°Π΄Π°Π½ΠΈΡ Π½Π΅Ρ."); readln(); end; end; - Yes, the problem is that each task has its own specifics, and it will have to be heavily piled up. I have seen the implementation somewhere through the case, but I still cannot find where. What is - either difficult or not suitable, but an elementary-optimal solution is needed ) - VaLenOK007
- Added by. In your case, Case will not greatly simplify the situation ... - knes
- oneReplace the word otherwise with else (there are no otherwise words in Pascal). - DelphiM0ZG
- Um ... confused with something, isn't it? Okay thank you. - knes
|