I have created this function for my game that should read a string, something like "3 Spade" and return its worth (this example it is worth 3 points).
The problem is that I get this error: no return statement found
Although when I write the same exact C++ code it runs without any error (I am coming from C++ background)
The Java code:
public static int getCardValue(String card)
{
for(int s=0; s != cardSuits.length; s++) //cardSuits is an array of strings
for(int r=0; r != cardRanks.length; r++)//cardRanks is an array of strings
{
String GeneratedCard = cardRanks[r] + " " + cardSuits[s];
if((GeneratedCard).equals(card))
{
if(r >= 0 && r <= 8) //number in array starts from 0(2) to 8(10)
{
return r;
}
else if( r >= 8 && r <= 12) //from 8(10) to 11(KING)
{
return 10;
}
}
else
return -1;
}
}
The same exact C++ code (tested and verified on this specific case for this post)
int Game::func(std::string card)
{
for (int s = 0; s != 3; s++) //cardSuits is an array of strings
for (int r = 0; r != 13; r++)//cardRanks is an array of strings
{
std::string GeneratedCard = cardRanks[r] + " " + cardSuits[s];
if (GeneratedCard==card)
{
if (r >= 0 && r <= 8) //number in array starts from 0(2) to 8(10)
{
return r;
}
else if (r >= 8 && r <= 12) //from 8(10) to 11(KING)
{
return 10;
}
}
else
return -1;
}
}
I am interested in 2 things:
- to know the working version of the java code
- why is there this difference between the c++ and the java code