Code:
#include <stdio.h>
#include <ctype.h>
int main (void)
{
char inputtedhand[64];
int NumC=0, NumD=0, NumS=0, NumH=0;
int handcount=0;
int tempvar;
char cardvalue[4];
int i=0, n=0, m=0;
int index=0, counter=0;
int z=0;
{
while((scanf("%c", &inputtedhand[z])>0))
{
inputtedhand[z]=toupper(inputtedhand[z]);
z++;
}
}
while(counter++<=1)
{
scanf( "%15c", &inputtedhand );
printf( "Found %s \n", inputtedhand );
for(i==0; i<15; i+=3)
{ m=(i+1);
n=(m+1);
scanf("%c", &inputtedhand[i]);
scanf("%c", &inputtedhand[m]);
scanf("%c", &inputtedhand[n]);
if (inputtedhand[i]==50){
printf( "The two of "); tempvar=2;
/* The the first value if a 2, "The two of" will be dsplayed at the output, and the number 2 will be stored as a temporary variable for later */
}else if (inputtedhand[i]==51){
printf( "The three of "); tempvar=3;
}else if (inputtedhand[i]==52){
printf( "The four of "); tempvar=4;
}else if (inputtedhand[i]==53){
printf("The five of "); tempvar=5;
}else if ( inputtedhand[i]==54){
printf("The six of "); tempvar=6;
}else if ( inputtedhand[i]==55){
printf("The seven of "); tempvar=7;
}else if ( inputtedhand[i]==56){
printf("The eight of "); tempvar=8;
}else if (inputtedhand[i]==57){
printf("The nine of "); tempvar=9;
}else if ( inputtedhand[i]==48){
printf("The ten of "); tempvar=10;
}else if (inputtedhand[i]==74){
printf("The Jack of "); tempvar=11;
}else if (inputtedhand[i]==81){
printf("The Queen of "); tempvar=12;
}else if (inputtedhand[i]==75){
printf("The King of "); tempvar=13;
}else if (inputtedhand[i]==65){
printf("The Ace of "); tempvar=14;
}else{
printf("%c",inputtedhand[i]); printf("is not recognised\n ");
}
if (inputtedhand[m]==67){
printf("Clubs\n"); NumC++;
/* This will complete the name for the first card, eg. "The two of Clubs" and counts the number of clubs there has been, this will be useful then looking for flushes */
}else if (inputtedhand[m]==68){
printf("Diamonds\n"); NumD++;
}else if (inputtedhand[m]==104){
printf("Hearts\n"); NumH++;
}else if (inputtedhand[m]==83){
printf("Spades\n"); NumS++;
}else{
printf(" SUIT "); printf("%c",inputtedhand[m]); printf(" not recognised\n");
}
cardvalue[index]=tempvar;
index++;
}
int flush=0;
if((NumH==5) || (NumC==5) || (NumD==5) || (NumS==5)){
flush=1;
}else{
flush=0;
}
int outside, inside, first, second;
{
for(outside=4; outside>0; outside--)
/* A loop that counts from 4 down to 0 as the algorithm passes through each term in the array */
{
for(inside=0; inside<outside; inside++)
{
first= cardvalue[inside];
second= cardvalue[inside+1];
if (first>second)
{
cardvalue[inside]=second;
cardvalue[inside+1]=first;
/* This is what makes the swap between the terms, if it is needed, the largest term should end up in position 4 of the array */
}
}
}
}
printf("%d", cardvalue[0]);
printf(" (0)\n");
printf("%d", cardvalue[1]);
printf(" (1)\n");
printf("%d", cardvalue[2]);
printf(" (2)\n");
printf("%d", cardvalue[3]);
printf(" (3)\n");
printf("%d", cardvalue[4]);
printf(" (4)\n");
int pair=0, pair1=0, pair2=0, pair3=0, pair4=0;
if(cardvalue[0]==cardvalue[1]){
pair1++; pair++;
}if(cardvalue[1]==cardvalue[2]){
pair2++; pair++;
}if(cardvalue[2]==cardvalue[3]){
pair3++; pair++;
}if(cardvalue[3]==cardvalue[4]){
pair4++; pair++;
}
int straight=0, straightflush=0, royalflush=0, fourkind=0, fullhouse=0, threekind=0, twopair=0, highcard=1;
if ((cardvalue[2]==cardvalue[1]+1) && cardvalue[3]==(cardvalue[2]+1) && cardvalue[1]==(cardvalue[0]+1) && (cardvalue[4]==(cardvalue[3]+1) || (cardvalue[0]==2 && cardvalue[4]==14)))
{
if((NumH==5) || (NumD==5) || (NumS==5) || (NumC==5))
{
if(cardvalue[0]==10)
{
royalflush++;
}else{
straightflush++;
}
}else{
straight++;
}
}else{
if ((pair1==1 && pair2==1 && pair4==1) || (pair1==1 && pair3==1 && pair4==1)){
/*This stage tests every posibility for getting a full house, if the criteria is met, the the number the counter for fullhouse is at, is incremented by one*/
fullhouse++;
}else if ((pair1 == 1 && pair2 == 1 && pair3 == 1) || (pair4 == 1 && pair3 == 1 && pair2 == 1)){
fourkind++;
}else if ((pair1 == 1 && pair2 == 1) || (pair2 == 1 && pair3 == 1) || (pair3 == 1 && pair4 == 1)) {
threekind++;
}else if ((pair1 == 1 && pair3 == 1) || (pair1 == 1 && pair3 == 1) || (pair1 == 1 && pair4 == 1) || (pair2 == 1 && pair4 == 1)){
twopair++;
}else{
if((NumH == 5) || (NumC == 5) || (NumD == 5) || (NumS == 5)){
flush++;
}else{
highcard++;
}
}
}
int scorehand[2];
while(1)
{
if ((royalflush)>=1){
/* When we see a yroyal flush we increment the count of a royal flush by 1, so here, by comparing to its initial value, 0. We can see if that had was a royal flush */
printf("\n The hand is a Royal Flush!!\n");
scorehand[counter]=(135+cardvalue[4]); break;
}else if((straightflush)>=1){
printf("\n The hand is the Straight Flush!\n");
scorehand[counter]=(120+cardvalue[4]);break;
}else if((fourkind)>=1){
printf("\n The hand is a Four of a Kind!\n");
scorehand[counter]=(105+cardvalue[4]);break;
}else if((fullhouse)>=1){
printf("\n The hand is a Full House\n");
scorehand[counter]=(90+cardvalue[4]); break;
}else if((flush)>=1){
printf("\n The hand is a Flush\n");
scorehand[counter]=(75+cardvalue[4]); break;
}else if((straight)>=1){
printf("\n The hand is a Straight\n");
scorehand[counter]=(60+cardvalue[4]); break;
}else if((threekind)>=1){
printf("\n The hand is a Three of a Kind\n");
scorehand[counter]=(45+cardvalue[4]);break;
}else if((twopair)>=1){
printf("\n The hand is a Two Pair\n");
scorehand[counter]=(30+cardvalue[4]); break;
}else if((pair)>=1){
printf("\nThe hand is a pair\n");
scorehand[counter]=(15+cardvalue[4]); break;
}else if((highcard)>=1){
printf("\n The hand is a High Card\n");
scorehand[counter]=cardvalue[4]; break;
}else{
printf("\n The hand scores 0 (this should not happen)");
/* This is to ensure the above has been executed as planned, if this comes uop then there is an error */
}
}
printf("%d", scorehand[1]);
printf("%d", scorehand[2]);
{
if (scorehand[1]>scorehand[2]){
puts("Player 1 is the winner!");
}
else if (scorehand[2]>scorehand[1]){
puts("Player 2 is the winner!");
}
else if(scorehand[1]==scorehand[2]){
puts("It's a draw :(");
}
else puts("this shouldnt happen");
}
}
}
Thanks for any help i get