In: Computer Science
Here is the C++ code to the given question.
Sample outputs are added at the end.
Code:
#include <iostream>
#include<string>
using namespace std;
/*function to get english word for card value*/
string getEnglishWord(int number){
string words[]={"none","ace","two","three","four","five","six","seven","eight","nine","ten","jack","queen","king"}; /*defines a string array of english words for card values*/
return words[number]; /*returns appropriate word for a given card*/
}
/*function to sort an array*/
void sort(int* inputCards){
int temp;
for(int i=0;i<3;i++)
{
for(int j=i+1;j<3;j++)
{
if(inputCards[i]>inputCards[j])
{
temp =inputCards[i];
inputCards[i]=inputCards[j];
inputCards[j]=temp;
}
}
}
}
int main()
{
int inputCards[3]; /*integer array to store input values for cards*/
cout<<"Enter input cards[1:13]: ";
for(int i=0;i<3;i++){
cin>>inputCards[i]; /*takes input from user*/
}
sort(inputCards); /*calls sort function to sort integer array*/
if(inputCards[0]==inputCards[1] && inputCards[0]==inputCards[2]){ /*check if all three values are equal*/
if(inputCards[0]==6)
cout<<"\nYou have three "<<getEnglishWord(inputCards[0])<<"es.";
else
cout<<"\nYou have three "<<getEnglishWord(inputCards[0])<<"s.";
}
else if(inputCards[0]==1 && inputCards[1]==12 && inputCards[2]==13){ /*special case for three successive values*/
cout<<"You have an "<<getEnglishWord(inputCards[0])<<"-high straight.";
}
else if(inputCards[0]+1==inputCards[1] && inputCards[1]+1==inputCards[2]){ /*check if three cards form a straight*/
if(inputCards[2]==8 || inputCards[2]==1) /*check if value is 8 or 1(to find article 'a' or 'an')*/
cout<<"\nYou have an "<<getEnglishWord(inputCards[2])<<"-high straight.";
else
cout<<"\nYou have a "<<getEnglishWord(inputCards[2])<<"-high straight.";
}
else if(inputCards[0]==inputCards[1]){ /*check if two cards are equal*/
if(inputCards[0]==6)
cout<<"\nYou have a pair of "<<getEnglishWord(inputCards[0])<<"es.";
else
cout<<"\nYou have a pair of "<<getEnglishWord(inputCards[0])<<"s.";
}
else if(inputCards[1]==inputCards[2]){ /*check if two cards are equal*/
if(inputCards[1]==6)
cout<<"\nYou have a pair of "<<getEnglishWord(inputCards[1])<<"es.";
else
cout<<"\nYou have a pair of "<<getEnglishWord(inputCards[1])<<"s.";
}
else{
if(inputCards[2]==8 || inputCards[2]==1) /*check if value is 8 or 1(to find article 'a' or 'an')*/
cout<<"\nYou have an "<<getEnglishWord(inputCards[2])<<".";
else
cout<<"\nYou have a "<<getEnglishWord(inputCards[2])<<".";
}
return 0;
}
Sample output-1:

Sample output-2:

Sample output-3:

Sample output-4:

i hope it helps..
If you have any doubts please comment and please don't dislike.
PLEASE GIVE ME A LIKE. ITS VERY IMPORTANT FOR ME