### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: pascal a bit trouble with program :(  (Read 10908 times)

#### burak

• New member
• Posts: 5
##### pascal a bit trouble with program :(
« on: November 07, 2014, 03:34:41 pm »
Hello, i have written program like this ...

Program j;
var f, g,a, b, c, m, i:integer;

begin
read1n (f, g)
for i:=2 to g do
for a:=1 to 9 do
for b:=1 to 9 do
for c:=1 to 9 do
begin
m:a*100+b*10+c;
if (m mod a=0) and
(m mod b=0) and
(m mod c=0) then
write1n(' ', m);
end;
read1n;
end.

But its not working right ... u can run it but it will find weird numbers )

Can anyone help me out ??
May some one check the program and correct it please ?

#### burak

• New member
• Posts: 5
##### Re: pascal a bit trouble with program :(
« Reply #1 on: November 07, 2014, 04:06:02 pm »
A positive integer N is called a " fair " if it is divisible by each of its digits. For example, the number 132 is fair , because it is divisible by 1 , 3 and 2. In contrast the number 123 is not fair, since , although divisible by 1 and 3 but not divisible by 2. Write a function that determines whether a fair number N ( N the parameter is a function). Next, write a program which uses this function finds and displays all the honest numbers range from A to B, including ( value of A, B will be awarded to the entry of the program - are positive integers from the range of data type integer.

#### Bart

• Hero Member
• Posts: 3939
##### Re: pascal a bit trouble with program :(
« Reply #2 on: November 07, 2014, 04:35:59 pm »
First describe the steps needed to accomplish this task.

Here are the first few steps (dont worry about the code yet):
- get all the digits out of a number (e.g. 1231 -> 1 and 2 and 3)
- try if the number can be divided by all of the digits (what to do if a number contains a zero?)

This basically describes the algorithm for determining if a number is "fair"

Do the same (describing the steps) for the procedure that determines that for a range of numbers from A to B.

After that translate each step into Pascal code, you may want to look into sets (and the operator in), div, mod.

Try to compile the code, show us the code and any errors in it.
At that stage we will help.

We won't do your assigment for you.

Bart

#### burak

• New member
• Posts: 5
##### Re: pascal a bit trouble with program :(
« Reply #3 on: November 07, 2014, 04:51:30 pm »
Well, i have only like a day left so i have to ask if there is any chance to pay for the program ?? If yes how much it may cost and how can i pay :p

#### Bart

• Hero Member
• Posts: 3939
##### Re: pascal a bit trouble with program :(
« Reply #4 on: November 07, 2014, 05:22:42 pm »
Well, i have only like a day left

Well, start then.
It is a trivial task.

Break down the problem in steps.
Post it here, get feedback.

Write code.
Post it her, get feedback.

Should not take you more than a few hours.

so i have to ask if there is any chance to pay for the program ?? If yes how much it may cost and how can i pay :p

I guess this is either a joke, or you are not willing to learn anything from you assignement at all.
If the latter is the case, I will do it for you if you promise me two things:
• Never do any programming in your life ever!
• Never work in healthcare, given your current attitude towards learning. You will kill people.

I require €500 to be paid to the Lazarus PayPal account (and proof that it has been  paid, since I don't have access to that account.

Bart

#### wp

• Hero Member
• Posts: 7620
##### Re: pascal a bit trouble with program :(
« Reply #5 on: November 07, 2014, 05:39:32 pm »
@Bart: Excellent answer!
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

#### ahiggins

• Jr. Member
• Posts: 92
##### Re: pascal a bit trouble with program :(
« Reply #6 on: November 07, 2014, 05:47:37 pm »
@bart Legend!

#### Leledumbo

• Hero Member
• Posts: 8273
• Programming + Glam Metal + Tae Kwon Do = Me
##### Re: pascal a bit trouble with program :(
« Reply #7 on: November 07, 2014, 07:49:11 pm »
What is wrong with education? Does it emphasize on grade too much as opposed to knowledge gain such that we have to deal with this kind of student? It happens nearly everywhere and I'm SICK of it. A grade should be able to represent the actual knowledge and skill of the owner. If your grade is F and you can barely understand what you code, then that's fair. But if you have A while you don't even understand your code, WHAT THE FUCK IS THAT???!!! I'm glad companies nowadays are not using GPA blindly to select for employees. Technical test has a much bigger portion now. A graduate with good or even great GPA but unemployed? It's YOUR fault!

#### Bart

• Hero Member
• Posts: 3939
##### Re: pascal a bit trouble with program :(
« Reply #8 on: November 08, 2014, 01:35:07 am »
I attached a working project.
I dare you to submit it to your teacher though, it's complexity will be noticably above your skills-level.

Amongs others it deals with numbers of arbitrary size (up to 2000000000 digitis long), and adjusts for quantum fluctuations in computer hardware.

Just check it out.

Here's how to compile it:

Code: [Select]
`C:\Users\Bart\LazarusProjecten\ConsoleProjecten\fair>fpc longfair.lprFree Pascal Compiler version 2.6.4 [2014/03/06] for i386Copyright (c) 1993-2014 by Florian Klaempfl and othersTarget OS: Win32 for i386Compiling longfair.lprCompiling ncalc.ppCompiling boolfactory.ppboolfactory.pp(46,14) Note: Virtual method "TCustomBoolFactory.ToString:AnsiString;" has a lower visibility (private) than parent class TObject (public)Compiling expressions.ppexpressions.pp(42,28) Warning: Constructing a class "TBoolFactory" with abstract method "AsString"expressions.pp(55,28) Warning: Constructing a class "TBoolFactory" with abstract method "AsString"ncalc.inc(458,3) Note: Local variable "i" not usedncalc.inc(458,6) Note: Local variable "LucMin1" not usedncalc.inc(458,15) Note: Local variable "LucMin2" not usedncalcdiv.inc(82,8) Note: Local variable "_N1" is assigned but never usedncalcdiv.inc(183,8) Note: Local variable "ADiv" is assigned but never usedncalc.inc(1262,3) Note: Local variable "RomanValues" not usedLinking longfair.exe3932 lines compiled, 3.1 sec , 154448 bytes code, 46556 bytes data2 warning(s) issued7 note(s) issued`
And heres how to run it (check the output below to see that it works):
Code: [Select]
`C:\Users\Bart\LazarusProjecten\ConsoleProjecten\fair>longfair 10 256Listing all "fair" numbers from 10 to 256Found a fair number: 11Found a fair number: 12Found a fair number: 15Found a fair number: 22Found a fair number: 24Found a fair number: 33Found a fair number: 36Found a fair number: 44Found a fair number: 48Found a fair number: 55Found a fair number: 66Found a fair number: 77Found a fair number: 88Found a fair number: 99Found a fair number: 111Found a fair number: 112Found a fair number: 115Found a fair number: 122Found a fair number: 124Found a fair number: 126Found a fair number: 128Found a fair number: 132Found a fair number: 135Found a fair number: 144Found a fair number: 155Found a fair number: 162Found a fair number: 168Found a fair number: 175Found a fair number: 184Found a fair number: 212Found a fair number: 216Found a fair number: 222Found a fair number: 224Found a fair number: 244Found a fair number: 248`
I'm awaiting the  €500 ...

Bart

#### BigChimp

• Hero Member
• Posts: 5740
• Add to the wiki - it's free ;)
##### Re: pascal a bit trouble with program :(
« Reply #9 on: November 08, 2014, 09:42:08 am »
Ah, yes, that's powerful code. I recognize it from your earlier posts.

Let's see whether the 500€ is paid.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

#### Leledumbo

• Hero Member
• Posts: 8273
• Programming + Glam Metal + Tae Kwon Do = Me
##### Re: pascal a bit trouble with program :(
« Reply #10 on: November 08, 2014, 12:43:34 pm »
I attached a working project.
I dare you to submit it to your teacher though, it's complexity will be noticably above your skills-level.

Amongs others it deals with numbers of arbitrary size (up to 2000000000 digitis long), and adjusts for quantum fluctuations in computer hardware.

Just check it out.
Briliant!

#### burak

• New member
• Posts: 5
##### Re: pascal a bit trouble with program :(
« Reply #11 on: November 08, 2014, 01:14:50 pm »
Well, thanks for your hateful speech ... i m really ashamed that i m trying solve this example for my gf becouse she have to ride to school fucking 3 hours per day only there and then back. She really have time to solve pascal when nobody i know use that at work or anywhere thanks for your ironic or should i say phatetic code rly .. i already paid 28\$ for it and yes i feel so bad for doing so .. "haha". I study psychology myself so yes i wont ever be using this at real life thanks for advice mr. Have a nice day anyway ... bye.

#### BigChimp

• Hero Member
• Posts: 5740
• Add to the wiki - it's free ;)
##### Re: pascal a bit trouble with program :(
« Reply #12 on: November 08, 2014, 01:41:25 pm »
Rhetorical question (we already know the answer): do the words "cheating" and "academic integrity" mean anything to you?
« Last Edit: November 08, 2014, 01:45:01 pm by BigChimp »
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

#### Bart

• Hero Member
• Posts: 3939
##### Re: pascal a bit trouble with program :(
« Reply #13 on: November 08, 2014, 02:03:06 pm »
... thanks for your ironic or should i say phatetic code rly

First of all. You never even tried to answer my first questions, which were in fact a well meant attempt to help you solve this problem.
Second: my posted code does the job perfectly well, and it does that for very large numbers (for which most programming languages do not have a native type).

You might have learnt from studying the code that the essence of the program was:
• Make a function that extracts all digits from a given number
• Make a function that divides a given number by all of it's digits: if either some digit is 0, or the division by a digit has a remainder then the number is not fair
• Make a procedure that runs this code on a range of numbers (Start to Stop)
• Make a procedure that asks the user what Start and Stop should be, so the program is flexible
• Stick all these pieces together

Wether or not this code is efficient is up for debate.
...to solve pascal when nobody i know use that at work or anywhere...

This does not really matter now, does it?
All programming starts with analyzing the problem and breaking it down into small pieces.

Or are you telling me you (or your gf) could have written this code in C, Basic, Java, PHP or any other programming language, but just not in Pascal?

.. i already paid 28\$ for it and yes i feel so bad for doing so .. "haha". I study psychology myself so yes i wont ever be using this at real life ...

Well, your unwillingness to analyse a problem,  your stinginess when it comes to presenting the truth, your willingness to defraude, your inability to accept sincere help when offered to you and your inability to distinguish said offer from the irony that came with it, makes me pitty the patient that has the misfortune to fall into your hands.

I have no doubt however that you will have a glorious career, you seem to have all the right competencies for it.

Bart

#### Leledumbo

• Hero Member
• Posts: 8273
• Programming + Glam Metal + Tae Kwon Do = Me
##### Re: pascal a bit trouble with program :(
« Reply #14 on: November 08, 2014, 02:13:26 pm »
For a psychology student, he doesn't seem to have the attitude of a psychologist. Nevermind, programming world doesn't need people like that. Despite he means to help, he actually kills his girlfriend's future. I think GPA should be stripped out of a CV selection. Links to cloud repositories where we can analyze code commits along with resulting application is a better way to select good programmers.