# a case statement with an array of shortint

Hi,
i have an array of 4 shortint
2, 5, 7, 9

and i have to check combination of those 4 shortint of should i proceed with an case statement
i would like to do something like this

Case Digits Of
2, 4, 6, 7: WriteLN ...;
5, 9, 7, 8: ... ;
9, 4, 1, 5; ... ;
end;

how should i do ???
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:

Are you trying to do something for each set of 4 digits?

mlmcc
0
Author Commented:
yes something like that
i just want to comment the digits following their combination
it's to make a blackjack game;
first the player try to guess the 4 digits
then the computer generates 4 random numbers between 0 and 10
and the program should compare the to arrays of 4 numbers
that's why the combination is important

i need a way to compare the 2 sets of arrays
i tought to use a case statement but i don't know how to place condition with a whole array

could you help me ?
if you have some more question just tell me i'm paying pretty much time on this question

elvis
0
Commented:
What you could do is 'compose' a unique number of the 4 digits and test the case statement for this number. Example:

var
A,B,C,D : shortint;
N : longint;

N := A shl 24 or B shl 16 or C shl 8 or D;
case N of
...

It's easiest to show this with hex numbers, so for your example this becomes:

Case N Of
\$02040607: WriteLN ...;
\$05090708: ... ;
\$09040105; ... ;
end;

- Rob.
0
Author Commented:
intresting remark
but i don't know that much of pascal
but what if for example
i transform my digit-array in Char-array en then just put them together wouldn't it be as succesfull as your method but more simple ???
i don't know something like

FOR i:=1 TO 4 DO
begin
Temp:=Random(10);
Digits[i]:=temp;
end;

FOR j:=1 TO 4 DO
Number:=Digits[j]+Number;

Case Number OF
4586: ...

????

0
Author Commented:
FORGET ABOUT WHAT I SAID !
i found lots and lots of mistake in it
i found something else

a snip of declaration would be

Var
i, Temp1, temp2:ShortInt;
digit:Array[1..4] Of Char;

a snip of my code to generate my 4 digits between 0 and 10 and to put them into Characters

FOR i:=1 TO 4 DO
Begin
Temp1:=Random(10);       {let take for Temp1 = 5}
Temp2:=Ord(Temp1);       {temp2 should be 53 according to the ASCII table}
Digit[i]:=Chr(Temp2);       {Digit[i] should be 5 again but a Character }
End;

and now to get a little String

Function Combination:String;
Var j:ShortInt;
Begin
Combination:=0;
FOR j:=1 TO 4 DO
Combination:=Combination+Digit[i];
End;

and then i can handle with my combination ???
isn't that something who could be possible ???
i know it's not the way you would solve it but i'm only 15 years old and i just starting with programming

Elvis
0
Commented:
Depending on the Pascal you are using there may be a VAL procedure to convert the string to number.
Var
Num1 : Integer;
Error : Integer;

Val(Combination,Num1,Error);

Num1 will have the value of the string
Error will indicate the position of a bad digit.  0 indicates it was a numeric string.

Case Num1 of
1234:
2468:

etc

mlmcc
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
thanks to both of you bye
Elvis
0
Commented: