In my application, I have many IF statements that could be optimizing, but for the life of me can’t work out a good possible solution without errors.
My current code:
if (User_XP > -1){User_level.setText("1");Minimum_Level= Level1; Maximum_level = Level2;}
if (User_XP > Level1){User_level.setText("1");Minimum_Level= Level1; Maximum_level = Level2;}
if (User_XP > Level2){User_level.setText("2");Minimum_Level = Level2; Maximum_level = Level3;}
if (User_XP > Level3){User_level.setText("3");Minimum_Level = Level3; Maximum_level = Level4;}
if (User_XP > Level4){User_level.setText("4");Minimum_Level = Level4; Maximum_level = Level5;}
if (User_XP > Level5){User_level.setText("5");Minimum_Level = Level5; Maximum_level = Level6;}
if (User_XP > Level6){User_level.setText("6");Minimum_Level = Level6; Maximum_level = Level6;}
if (User_XP > Level7){User_level.setText("7");Minimum_Level = Level7; Maximum_level = Level6;}
if (User_XP > Level8){User_level.setText("8");Minimum_Level = Level8; Maximum_level = Level6;}
if (User_XP > Level9){User_level.setText("9");Minimum_Level = Level9; Maximum_level = Level6;}
The idea of it is to work out a users level from a game, and from that create a percentage. But this area of coding is really not efficient as it can create multiple errors, anyone got any tips on a possible solution?
Please ask if more information is needed.
Perhaps store your level experience requirements in an array and use a loop.