Originally Posted by
vart
only #include <stdio.h> is used
main should be declared as
int main(int argc, char* argv[])
variables should be declared locally and initialized
Code:
(c[d]==12 && c[d]==1)
Do you understand your own code?
etc
Well my working program seems to think so!!
4 straights found, 2 going up and two going down.
Which is correct with the data I put in the array.
Might be a problem with some of the end straights containing aces.
Not tested yet.
You don't have my compiler.
Code:
(c[d]==12 && c[d]==1)
Well spotted ty.
Code:
(c[d]==12 && c[d]+1==1)
I think this is not far off!!
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <io.h>
#include <fcntl.h>
#include <errno.h>
int c[7];
int a,b,x,d,e;
main(argc,argv)
int argc;
char *argv[];
{
printf("\n Start");
c[0]=3;
c[1]=7;
c[2]=3;
c[3]=12;
c[4]=5;
c[5]=4;
c[6]=6;
for (a=0; a<7; a++){
if (c[a]>10) continue;
for (b=0; b<7; b++){//first card in straight
if (c[b]==c[a]+1) {//second
for (x=0; x<7; x++){
if (c[x]==(c[b])+1) {//third
for (d=0; d<7; d++){
if (c[d]==c[x]+1) {//fourth
for (e=0; e<7; e++){
if ((c[e]==c[d]+1) || (c[d]==12 && c[d]+1==1)) {//fifth
printf("\n Straight up"); //fifth includes 9,10,11,12,1
}
}
}
}
}
}
}
}
}
for (a=0; a<7; a++){
if ((c[a]<5 ) && (c[a]!=1)) continue;
if (c[a]==1) c[a]=13;
for (b=0; b<7; b++){//first
if (c[b]==c[a]-1) {//second
for (x=0; x<7; x++){
if (c[x]==c[b]-1) {//third
for (d=0; d<7; d++){
if (c[d]==c[x]-1) {//fourth
for (e=0; e<7; e++){
if (c[e]==c[d]-1) {//fifth
printf("\n Straight down");
}
}
}
}
}
}
}
}
}
}/*main */
Output:-
Code:
Start
Straight up
Straight up
Straight down
Straight down