I'm trying to write a program that will compare 5 integer values and put them in smallest to biggest order. So far I can only find the smallest and biggest integer. I'm stucking with the other 3 remain in the middle. Here is my code look like:
Code:
const int ArraySize = 5;
int getSmallvalue(int card[], int size)
{
int order;
int small = 1;
for(order = 0; order < size; order++)
{
if(card[small] >= card[order])
small = order;
}
return small;
}
int getBigvalue(int card[], int size)
{
int order;
int big = 13;
for(order=0; order<size; order++)
{
if(card[big] <= card[order])
big = order;
}
return big;
}
int main()
{
start:
cout<<"Enter 5 cards: "<<endl;
for(int j=0; j<ArraySize; j++)
cin>>CardInput[j];
for(j=0; j<ArraySize; j++)
{
if((CardInput[j] < 1) || (CardInput[j] > 52))
{
cout<<"The card cannot be smaller than 1 or bigger than 52"<<endl;
goto start;
}
}
for(j=0; j<ArraySize; j++)
{
if((CardInput[j] > 0) && (CardInput[j] <= 13)){
Diamond += 1;
}
if((CardInput[j] >= 14) && (CardInput[j] <= 26)){
Heart += 1;
CardInput[j] -= 13;
}
if((CardInput[j] >= 27) && (CardInput[j] <= 39)){
Spade += 1;
CardInput[j] -= 26;
}
if((CardInput[j] >= 40) && (CardInput[j] <= 52)){
Club += 1;
CardInput[j] -= 39;
}
}
cout<<"\nSmallest card is: "<<CardInput[getSmallvalue(CardInput, ArraySize)]<<endl;
cout<<"\nBiggest card is: "<<CardInput[getBigvalue(CardInput, ArraySize)]
}
The biggest number is 13 and smallest is 1. The number above 13 will be subtract by 13, 26..., so that the value always stays between 1 and 13
Please help me, and I really don't want to bunch of "if" and "else" statements. They are pain and so confuse in this matter. Thanks