Solved

a case statement with an array of shortint

Posted on 2003-10-25
8
239 Views
Last Modified: 2010-04-16
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 ???
thanks in advance
0
Comment
Question by:Elvis1
  • 4
  • 3
8 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 9621791
I don't understand your problem?

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

mlmcc
0
 

Author Comment

by:Elvis1
ID: 9622686
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

thanks in advance bye
elvis
0
 
LVL 2

Assisted Solution

by:MrT-RSI
MrT-RSI earned 20 total points
ID: 9622972
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:Elvis1
ID: 9623477
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: ...

????

thanks in advance
0
 

Author Comment

by:Elvis1
ID: 9623856
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

thanks in advance
Elvis
0
 
LVL 100

Accepted Solution

by:
mlmcc earned 30 total points
ID: 9624079
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
 

Author Comment

by:Elvis1
ID: 9625447
thanks to both of you bye
Elvis
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 9630819
Glad I could help

mlmcc
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
help with delphi code 6 481
How to send email in delphi with image 4 595
MAPI Error1: User cancelled request ? 7 1,208
TEdit.SetFocus trouble 3 174
Facebook has became the #1 social media platform. People share many funny videos there, yet you don't know how to download them? Now you can download Videos from Facebook in just 3 simple steps.
Active Directory security has been a hot topic of late, and for good reason. With 90% of the world’s organization using this system to manage access to all parts of their IT infrastructure, knowing how to protect against threats and keep vulnerabil…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question