Board index » delphi » ??? What's wrong?

??? What's wrong?

I wrote a simple script that is suppose to output integers that match
there position, but something is wrong.  The output return is just the
"*", HELP!

Please...

---------------------attached code-------------------------

program PositionToInteger; {This program takes a random integer input
                            and matches it's value to position}
var val1: longint;
    position: integer;

const Alength:longint=10; {Maximum number of integers acceptable}

function IfTheyMatch (place: longint;
                      position: longint):boolean;
var PositionPlace: longint;
    begin
         PositionPlace:=1+(ord(position)-ord(0));
         IfTheyMatch:=PositionPlace = place
    end; {PositionPlace}

begin
{Read integer inputs, and place them in an ordered line}
writeln ('Enter a string of 10 numbers, randomly,');
writeln ('including "0", with "9" being the largest value: ');
{Check the value against its position, if they match, then output those
that do}
     for position:=1 to (Alength) do begin
         read (val1);
         if IfTheyMatch (position, val1)
            then begin write (val1) end
            else begin write ('*')
         end; {if}
     end; {for}
writeln;

end.
{End program}

 

Re:??? What's wrong?


Hello,

Quote
>I wrote a simple script that is suppose to output integers that match
>there position, but something is wrong.  The output return is just the
>"*", HELP!

>Please...

>---------------------attached code-------------------------

>program PositionToInteger; {This program takes a random integer input
>                            and matches it's value to position}
>var val1: longint;
>    position: integer;

>const Alength:longint=10; {Maximum number of integers acceptable}

>function IfTheyMatch (place: longint;
>                      position: longint):boolean;
>var PositionPlace: longint;
>    begin
>         PositionPlace:=1+(ord(position)-ord(0));
>         IfTheyMatch:=PositionPlace = place
>    end; {PositionPlace}

>begin
>{Read integer inputs, and place them in an ordered line}
>writeln ('Enter a string of 10 numbers, randomly,');
>writeln ('including "0", with "9" being the largest value: ');
>{Check the value against its position, if they match, then output those
>that do}
>     for position:=1 to (Alength) do begin
>         read (val1);

This read statement reads in the entire 10 digit input as a long
integer (causing a runtime error with TMT).  Making val1 a character
and altering IfTheyMatch accordingly should fix the problem.

Quote
>         if IfTheyMatch (position, val1)
>            then begin write (val1) end
>            else begin write ('*')
>         end; {if}
>     end; {for}
>writeln;

>end.
>{End program}

cu...

--
  Michael Langton <langtons.notthis...@manawatu.gen.nz>

{*word*16}ism Catalyst:
precti...@ultra-mail.com R...@treme.et em...@rerols.com
1...@becsplace.com tris...@hotmail.com r...@iemmc.org
b...@iemmc.org r...@{*word*104}promo.com HockeyU...@aol.com
maria...@hotmail.com

Re:??? What's wrong?


Mike,

Thanks, setting the var (val1) to 'char' and enclosing the ord start
point in '' fixed this problem.  

Again thanks,

Mark

Quote
Michael Langton wrote:

> Hello,
> >I wrote a simple script that is suppose to output integers that match
> >there position, but something is wrong.  The output return is just the
> >"*", HELP!

> >Please...

> >---------------------attached code-------------------------

> >program PositionToInteger; {This program takes a random integer input
> >                            and matches it's value to position}
> >var val1: longint;
> >    position: integer;

> >const Alength:longint=10; {Maximum number of integers acceptable}

> >function IfTheyMatch (place: longint;
> >                      position: longint):boolean;
> >var PositionPlace: longint;
> >    begin
> >         PositionPlace:=1+(ord(position)-ord(0));
> >         IfTheyMatch:=PositionPlace = place
> >    end; {PositionPlace}

> >begin
> >{Read integer inputs, and place them in an ordered line}
> >writeln ('Enter a string of 10 numbers, randomly,');
> >writeln ('including "0", with "9" being the largest value: ');
> >{Check the value against its position, if they match, then output those
> >that do}
> >     for position:=1 to (Alength) do begin
> >         read (val1);
> This read statement reads in the entire 10 digit input as a long
> integer (causing a runtime error with TMT).  Making val1 a character
> and altering IfTheyMatch accordingly should fix the problem.
> >         if IfTheyMatch (position, val1)
> >            then begin write (val1) end
> >            else begin write ('*')
> >         end; {if}
> >     end; {for}
> >writeln;

> >end.
> >{End program}

> cu...

> --
>   Michael Langton <langtons.notthis...@manawatu.gen.nz>

> {*word*16}ism Catalyst:
> precti...@ultra-mail.com R...@treme.et em...@rerols.com
> 1...@becsplace.com tris...@hotmail.com r...@iemmc.org
> b...@iemmc.org r...@{*word*104}promo.com HockeyU...@aol.com
> maria...@hotmail.com

Other Threads