How can I use percentages in a switch condition to represent player status based on health?Using a method from a different classBig Integer multiplication(recursion) in java stops without an error for input of size of the order of 2000 digits. Why?How to prevent cheating with Gamecih?Is it possible to merge these two queries?Finding number of digits before a decimal point in javaChoosing players based on percentageHow not to show the unknown/skipped results in extent reportswitch case array reading - javasoundHow can this method be changed to return a List of Strings rather than a String?Box2D (Processing): how to solve the 'Could not invoke the “beginContact()” method for some reason' error?

shebang or not shebang

What did Varys actually mean?

Crime rates in a post-scarcity economy

Gift for mentor after his thesis defense?

If quadruped mammals evolve to become bipedal will their breast or nipple change position?

In a series of books, what happens after the coming of age?

HTML folder located within IOS Image file?

How can I finally understand the confusing modal verb "мочь"?

Why did Gendry call himself Gendry Rivers?

Why doesn't a particle exert force on itself?

What does “two-bit (jerk)” mean?

Concatenate all values of the same XML element using XPath/XQuery

How does "politician" work as a job/career?

Does this website provide consistent translation into Wookiee?

Translation of "invincible independence"

How to get the decimal part of a number in apex

What does the copyright in a dissertation protect exactly?

Good introductory book to type theory?

Picking a theme as a discovery writer

Make me a minimum magic sum

Select list elements based on other list

A♭ major 9th chord in Bach is unexpectedly dissonant/jazzy

Why is the blank symbol not considered part of the input alphabet of a Turing machine?

Does restarting the SQL Services (on the machine) clear the server cache (for things like query plans and statistics)?



How can I use percentages in a switch condition to represent player status based on health?


Using a method from a different classBig Integer multiplication(recursion) in java stops without an error for input of size of the order of 2000 digits. Why?How to prevent cheating with Gamecih?Is it possible to merge these two queries?Finding number of digits before a decimal point in javaChoosing players based on percentageHow not to show the unknown/skipped results in extent reportswitch case array reading - javasoundHow can this method be changed to return a List of Strings rather than a String?Box2D (Processing): how to solve the 'Could not invoke the “beginContact()” method for some reason' error?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I should preface this by saying I'm VERY new to coding and Java in general; forgive my stupidity! I'm attempting to set up a status system for the player based on how much health they have, wherein their current Status is a String involved in a switch function which changes from "You are doing fine!" to "You are dying!". However, rather than doing it with single digits, I want to do it with percentage of health so the message does not change when they reach 50 or 25 percent health, whether the player has 50 or 10 health max.



Essentially, I want to make it so in place of single variables representing certain values of health in the switch function, percentages of PCHealth do. This is what I don't want, but what I know how to do:



int PCHealth = 10;
String Status = "";
switch (PCHealth)
case 5: Status = "You're fine!";
case 2: Status = "You're dying!";



Here's what I want sketched out in fake code:



int PCHealth = 10;
String Status = "';
switch (PCHealth)
case [50% of PCHealth] = "You're fine!";
case [20 % of PCHealth] = "You're dying!";



Thank you!










share|improve this question






















  • you can evaluate those values before switch and store it in a variable and then put that variable inside switch

    – Onkar Musale
    Mar 23 at 6:00


















0















I should preface this by saying I'm VERY new to coding and Java in general; forgive my stupidity! I'm attempting to set up a status system for the player based on how much health they have, wherein their current Status is a String involved in a switch function which changes from "You are doing fine!" to "You are dying!". However, rather than doing it with single digits, I want to do it with percentage of health so the message does not change when they reach 50 or 25 percent health, whether the player has 50 or 10 health max.



Essentially, I want to make it so in place of single variables representing certain values of health in the switch function, percentages of PCHealth do. This is what I don't want, but what I know how to do:



int PCHealth = 10;
String Status = "";
switch (PCHealth)
case 5: Status = "You're fine!";
case 2: Status = "You're dying!";



Here's what I want sketched out in fake code:



int PCHealth = 10;
String Status = "';
switch (PCHealth)
case [50% of PCHealth] = "You're fine!";
case [20 % of PCHealth] = "You're dying!";



Thank you!










share|improve this question






















  • you can evaluate those values before switch and store it in a variable and then put that variable inside switch

    – Onkar Musale
    Mar 23 at 6:00














0












0








0








I should preface this by saying I'm VERY new to coding and Java in general; forgive my stupidity! I'm attempting to set up a status system for the player based on how much health they have, wherein their current Status is a String involved in a switch function which changes from "You are doing fine!" to "You are dying!". However, rather than doing it with single digits, I want to do it with percentage of health so the message does not change when they reach 50 or 25 percent health, whether the player has 50 or 10 health max.



Essentially, I want to make it so in place of single variables representing certain values of health in the switch function, percentages of PCHealth do. This is what I don't want, but what I know how to do:



int PCHealth = 10;
String Status = "";
switch (PCHealth)
case 5: Status = "You're fine!";
case 2: Status = "You're dying!";



Here's what I want sketched out in fake code:



int PCHealth = 10;
String Status = "';
switch (PCHealth)
case [50% of PCHealth] = "You're fine!";
case [20 % of PCHealth] = "You're dying!";



Thank you!










share|improve this question














I should preface this by saying I'm VERY new to coding and Java in general; forgive my stupidity! I'm attempting to set up a status system for the player based on how much health they have, wherein their current Status is a String involved in a switch function which changes from "You are doing fine!" to "You are dying!". However, rather than doing it with single digits, I want to do it with percentage of health so the message does not change when they reach 50 or 25 percent health, whether the player has 50 or 10 health max.



Essentially, I want to make it so in place of single variables representing certain values of health in the switch function, percentages of PCHealth do. This is what I don't want, but what I know how to do:



int PCHealth = 10;
String Status = "";
switch (PCHealth)
case 5: Status = "You're fine!";
case 2: Status = "You're dying!";



Here's what I want sketched out in fake code:



int PCHealth = 10;
String Status = "';
switch (PCHealth)
case [50% of PCHealth] = "You're fine!";
case [20 % of PCHealth] = "You're dying!";



Thank you!







java






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 23 at 5:54









Jippy HereJippy Here

11




11












  • you can evaluate those values before switch and store it in a variable and then put that variable inside switch

    – Onkar Musale
    Mar 23 at 6:00


















  • you can evaluate those values before switch and store it in a variable and then put that variable inside switch

    – Onkar Musale
    Mar 23 at 6:00

















you can evaluate those values before switch and store it in a variable and then put that variable inside switch

– Onkar Musale
Mar 23 at 6:00






you can evaluate those values before switch and store it in a variable and then put that variable inside switch

– Onkar Musale
Mar 23 at 6:00













4 Answers
4






active

oldest

votes


















1














Just do it with if-else. Its very simple and good to understand.



public String getStatus(int PChealth, int maxValue) 
float percent = (PChealth * 1.0f) / maxValue;

if (percent > 75) return "great";
else if (percent > 50) return "mid";
else if (percent > 25) return "not good";
else if (PChealth == 0) return "dead";
else return "bad";



Side notes: The first if that evalute true will return the correct value.

Savvy?






share|improve this answer






























    1














    /*

    Things that you will need to know
    - integer division vs double
    - type casting
    - Math.ceil()

    # int division

    10/25 --> 0

    # double division

    10.0/25 --> 0.4

    # Math.ceil()

    Math.ceil(0.4) --> 1.0



    0-25 XXX
    25-50 fine
    50-75 good
    75-100 great

    */



    Play with this code, printout things that you don't understand or what value they are holding... I tried to keep things simple.



    public class MyClass 

    private static int maxHealth = 100;
    public static String getPlayerHealthStatus(double pHealth)

    String pHStatus = "";
    int pHealth_case = (int) Math.ceil( pHealth / (maxHealth / 4));

    switch (pHealth_case)
    case 4:
    pHStatus = "You're doing great!";
    break;

    case 3:
    pHStatus = "You're doing good!";
    break;

    case 2:
    pHStatus = "You're fine!";
    break;

    case 1:
    pHStatus = "You're dying!";
    break;

    case 0:
    pHStatus = "You died!";
    break;

    default:
    pHStatus = "invalid player health";


    return pHStatus;


    public static void main(String args[])
    int playerHealth = 90;
    System.out.println("player health: "+playerHealth+" status: "+getPlayerHealthStatus(playerHealth));

    playerHealth = 70;
    System.out.println("player health: "+playerHealth+" status: "+getPlayerHealthStatus(playerHealth));

    playerHealth = 40;
    System.out.println("player health: "+playerHealth+" status: "+getPlayerHealthStatus(playerHealth));

    playerHealth = 20;
    System.out.println("player health: "+playerHealth+" status: "+getPlayerHealthStatus(playerHealth));

    playerHealth = 0;
    System.out.println("player health: "+playerHealth+" status: "+getPlayerHealthStatus(playerHealth));




    Output:



    player health: 90 status: You're doing great!
    player health: 70 status: You're doing good!
    player health: 40 status: You're fine!
    player health: 20 status: You're dying!
    player health: 0 status: You died!





    share|improve this answer
































      0














      Its not possible to have expressions in case statements, use if-else statements or like @Onkar said store them in a separate variable.



      if-else should be cleaner for your use case.






      share|improve this answer
































        0














        I would store the max health in the variable MaxHealth then try the following switch! :)



        Here we have if statement in the switch statement, that will do case 1 if the health is between 0 and 20% and so on



        double PCHealth = __ ;

        switch (((0 <= PCHealth && PCHealth <= (0.2 * MaxHealth)) ? 0 :
        ((0.2 * MaxHealth) > PCHealth && (0.5 * MaxHealth) < PCHealth) ? 1 : 2)


        case 0:
        Status = "You're dying!";
        break;
        case 1:
        Status = "You're fine!";
        break;
        case 2:
        Status = "You're doing excelent";
        break;






        share|improve this answer

























          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55311044%2fhow-can-i-use-percentages-in-a-switch-condition-to-represent-player-status-based%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          4 Answers
          4






          active

          oldest

          votes








          4 Answers
          4






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Just do it with if-else. Its very simple and good to understand.



          public String getStatus(int PChealth, int maxValue) 
          float percent = (PChealth * 1.0f) / maxValue;

          if (percent > 75) return "great";
          else if (percent > 50) return "mid";
          else if (percent > 25) return "not good";
          else if (PChealth == 0) return "dead";
          else return "bad";



          Side notes: The first if that evalute true will return the correct value.

          Savvy?






          share|improve this answer



























            1














            Just do it with if-else. Its very simple and good to understand.



            public String getStatus(int PChealth, int maxValue) 
            float percent = (PChealth * 1.0f) / maxValue;

            if (percent > 75) return "great";
            else if (percent > 50) return "mid";
            else if (percent > 25) return "not good";
            else if (PChealth == 0) return "dead";
            else return "bad";



            Side notes: The first if that evalute true will return the correct value.

            Savvy?






            share|improve this answer

























              1












              1








              1







              Just do it with if-else. Its very simple and good to understand.



              public String getStatus(int PChealth, int maxValue) 
              float percent = (PChealth * 1.0f) / maxValue;

              if (percent > 75) return "great";
              else if (percent > 50) return "mid";
              else if (percent > 25) return "not good";
              else if (PChealth == 0) return "dead";
              else return "bad";



              Side notes: The first if that evalute true will return the correct value.

              Savvy?






              share|improve this answer













              Just do it with if-else. Its very simple and good to understand.



              public String getStatus(int PChealth, int maxValue) 
              float percent = (PChealth * 1.0f) / maxValue;

              if (percent > 75) return "great";
              else if (percent > 50) return "mid";
              else if (percent > 25) return "not good";
              else if (PChealth == 0) return "dead";
              else return "bad";



              Side notes: The first if that evalute true will return the correct value.

              Savvy?







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Mar 23 at 7:47









              user6537157user6537157

              388214




              388214























                  1














                  /*

                  Things that you will need to know
                  - integer division vs double
                  - type casting
                  - Math.ceil()

                  # int division

                  10/25 --> 0

                  # double division

                  10.0/25 --> 0.4

                  # Math.ceil()

                  Math.ceil(0.4) --> 1.0



                  0-25 XXX
                  25-50 fine
                  50-75 good
                  75-100 great

                  */



                  Play with this code, printout things that you don't understand or what value they are holding... I tried to keep things simple.



                  public class MyClass 

                  private static int maxHealth = 100;
                  public static String getPlayerHealthStatus(double pHealth)

                  String pHStatus = "";
                  int pHealth_case = (int) Math.ceil( pHealth / (maxHealth / 4));

                  switch (pHealth_case)
                  case 4:
                  pHStatus = "You're doing great!";
                  break;

                  case 3:
                  pHStatus = "You're doing good!";
                  break;

                  case 2:
                  pHStatus = "You're fine!";
                  break;

                  case 1:
                  pHStatus = "You're dying!";
                  break;

                  case 0:
                  pHStatus = "You died!";
                  break;

                  default:
                  pHStatus = "invalid player health";


                  return pHStatus;


                  public static void main(String args[])
                  int playerHealth = 90;
                  System.out.println("player health: "+playerHealth+" status: "+getPlayerHealthStatus(playerHealth));

                  playerHealth = 70;
                  System.out.println("player health: "+playerHealth+" status: "+getPlayerHealthStatus(playerHealth));

                  playerHealth = 40;
                  System.out.println("player health: "+playerHealth+" status: "+getPlayerHealthStatus(playerHealth));

                  playerHealth = 20;
                  System.out.println("player health: "+playerHealth+" status: "+getPlayerHealthStatus(playerHealth));

                  playerHealth = 0;
                  System.out.println("player health: "+playerHealth+" status: "+getPlayerHealthStatus(playerHealth));




                  Output:



                  player health: 90 status: You're doing great!
                  player health: 70 status: You're doing good!
                  player health: 40 status: You're fine!
                  player health: 20 status: You're dying!
                  player health: 0 status: You died!





                  share|improve this answer





























                    1














                    /*

                    Things that you will need to know
                    - integer division vs double
                    - type casting
                    - Math.ceil()

                    # int division

                    10/25 --> 0

                    # double division

                    10.0/25 --> 0.4

                    # Math.ceil()

                    Math.ceil(0.4) --> 1.0



                    0-25 XXX
                    25-50 fine
                    50-75 good
                    75-100 great

                    */



                    Play with this code, printout things that you don't understand or what value they are holding... I tried to keep things simple.



                    public class MyClass 

                    private static int maxHealth = 100;
                    public static String getPlayerHealthStatus(double pHealth)

                    String pHStatus = "";
                    int pHealth_case = (int) Math.ceil( pHealth / (maxHealth / 4));

                    switch (pHealth_case)
                    case 4:
                    pHStatus = "You're doing great!";
                    break;

                    case 3:
                    pHStatus = "You're doing good!";
                    break;

                    case 2:
                    pHStatus = "You're fine!";
                    break;

                    case 1:
                    pHStatus = "You're dying!";
                    break;

                    case 0:
                    pHStatus = "You died!";
                    break;

                    default:
                    pHStatus = "invalid player health";


                    return pHStatus;


                    public static void main(String args[])
                    int playerHealth = 90;
                    System.out.println("player health: "+playerHealth+" status: "+getPlayerHealthStatus(playerHealth));

                    playerHealth = 70;
                    System.out.println("player health: "+playerHealth+" status: "+getPlayerHealthStatus(playerHealth));

                    playerHealth = 40;
                    System.out.println("player health: "+playerHealth+" status: "+getPlayerHealthStatus(playerHealth));

                    playerHealth = 20;
                    System.out.println("player health: "+playerHealth+" status: "+getPlayerHealthStatus(playerHealth));

                    playerHealth = 0;
                    System.out.println("player health: "+playerHealth+" status: "+getPlayerHealthStatus(playerHealth));




                    Output:



                    player health: 90 status: You're doing great!
                    player health: 70 status: You're doing good!
                    player health: 40 status: You're fine!
                    player health: 20 status: You're dying!
                    player health: 0 status: You died!





                    share|improve this answer



























                      1












                      1








                      1







                      /*

                      Things that you will need to know
                      - integer division vs double
                      - type casting
                      - Math.ceil()

                      # int division

                      10/25 --> 0

                      # double division

                      10.0/25 --> 0.4

                      # Math.ceil()

                      Math.ceil(0.4) --> 1.0



                      0-25 XXX
                      25-50 fine
                      50-75 good
                      75-100 great

                      */



                      Play with this code, printout things that you don't understand or what value they are holding... I tried to keep things simple.



                      public class MyClass 

                      private static int maxHealth = 100;
                      public static String getPlayerHealthStatus(double pHealth)

                      String pHStatus = "";
                      int pHealth_case = (int) Math.ceil( pHealth / (maxHealth / 4));

                      switch (pHealth_case)
                      case 4:
                      pHStatus = "You're doing great!";
                      break;

                      case 3:
                      pHStatus = "You're doing good!";
                      break;

                      case 2:
                      pHStatus = "You're fine!";
                      break;

                      case 1:
                      pHStatus = "You're dying!";
                      break;

                      case 0:
                      pHStatus = "You died!";
                      break;

                      default:
                      pHStatus = "invalid player health";


                      return pHStatus;


                      public static void main(String args[])
                      int playerHealth = 90;
                      System.out.println("player health: "+playerHealth+" status: "+getPlayerHealthStatus(playerHealth));

                      playerHealth = 70;
                      System.out.println("player health: "+playerHealth+" status: "+getPlayerHealthStatus(playerHealth));

                      playerHealth = 40;
                      System.out.println("player health: "+playerHealth+" status: "+getPlayerHealthStatus(playerHealth));

                      playerHealth = 20;
                      System.out.println("player health: "+playerHealth+" status: "+getPlayerHealthStatus(playerHealth));

                      playerHealth = 0;
                      System.out.println("player health: "+playerHealth+" status: "+getPlayerHealthStatus(playerHealth));




                      Output:



                      player health: 90 status: You're doing great!
                      player health: 70 status: You're doing good!
                      player health: 40 status: You're fine!
                      player health: 20 status: You're dying!
                      player health: 0 status: You died!





                      share|improve this answer















                      /*

                      Things that you will need to know
                      - integer division vs double
                      - type casting
                      - Math.ceil()

                      # int division

                      10/25 --> 0

                      # double division

                      10.0/25 --> 0.4

                      # Math.ceil()

                      Math.ceil(0.4) --> 1.0



                      0-25 XXX
                      25-50 fine
                      50-75 good
                      75-100 great

                      */



                      Play with this code, printout things that you don't understand or what value they are holding... I tried to keep things simple.



                      public class MyClass 

                      private static int maxHealth = 100;
                      public static String getPlayerHealthStatus(double pHealth)

                      String pHStatus = "";
                      int pHealth_case = (int) Math.ceil( pHealth / (maxHealth / 4));

                      switch (pHealth_case)
                      case 4:
                      pHStatus = "You're doing great!";
                      break;

                      case 3:
                      pHStatus = "You're doing good!";
                      break;

                      case 2:
                      pHStatus = "You're fine!";
                      break;

                      case 1:
                      pHStatus = "You're dying!";
                      break;

                      case 0:
                      pHStatus = "You died!";
                      break;

                      default:
                      pHStatus = "invalid player health";


                      return pHStatus;


                      public static void main(String args[])
                      int playerHealth = 90;
                      System.out.println("player health: "+playerHealth+" status: "+getPlayerHealthStatus(playerHealth));

                      playerHealth = 70;
                      System.out.println("player health: "+playerHealth+" status: "+getPlayerHealthStatus(playerHealth));

                      playerHealth = 40;
                      System.out.println("player health: "+playerHealth+" status: "+getPlayerHealthStatus(playerHealth));

                      playerHealth = 20;
                      System.out.println("player health: "+playerHealth+" status: "+getPlayerHealthStatus(playerHealth));

                      playerHealth = 0;
                      System.out.println("player health: "+playerHealth+" status: "+getPlayerHealthStatus(playerHealth));




                      Output:



                      player health: 90 status: You're doing great!
                      player health: 70 status: You're doing good!
                      player health: 40 status: You're fine!
                      player health: 20 status: You're dying!
                      player health: 0 status: You died!






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Mar 25 at 18:34

























                      answered Mar 23 at 6:38









                      Tanmay jainTanmay jain

                      72949




                      72949





















                          0














                          Its not possible to have expressions in case statements, use if-else statements or like @Onkar said store them in a separate variable.



                          if-else should be cleaner for your use case.






                          share|improve this answer





























                            0














                            Its not possible to have expressions in case statements, use if-else statements or like @Onkar said store them in a separate variable.



                            if-else should be cleaner for your use case.






                            share|improve this answer



























                              0












                              0








                              0







                              Its not possible to have expressions in case statements, use if-else statements or like @Onkar said store them in a separate variable.



                              if-else should be cleaner for your use case.






                              share|improve this answer















                              Its not possible to have expressions in case statements, use if-else statements or like @Onkar said store them in a separate variable.



                              if-else should be cleaner for your use case.







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Mar 23 at 6:46

























                              answered Mar 23 at 6:39









                              HariUserXHariUserX

                              1,1231515




                              1,1231515





















                                  0














                                  I would store the max health in the variable MaxHealth then try the following switch! :)



                                  Here we have if statement in the switch statement, that will do case 1 if the health is between 0 and 20% and so on



                                  double PCHealth = __ ;

                                  switch (((0 <= PCHealth && PCHealth <= (0.2 * MaxHealth)) ? 0 :
                                  ((0.2 * MaxHealth) > PCHealth && (0.5 * MaxHealth) < PCHealth) ? 1 : 2)


                                  case 0:
                                  Status = "You're dying!";
                                  break;
                                  case 1:
                                  Status = "You're fine!";
                                  break;
                                  case 2:
                                  Status = "You're doing excelent";
                                  break;






                                  share|improve this answer





























                                    0














                                    I would store the max health in the variable MaxHealth then try the following switch! :)



                                    Here we have if statement in the switch statement, that will do case 1 if the health is between 0 and 20% and so on



                                    double PCHealth = __ ;

                                    switch (((0 <= PCHealth && PCHealth <= (0.2 * MaxHealth)) ? 0 :
                                    ((0.2 * MaxHealth) > PCHealth && (0.5 * MaxHealth) < PCHealth) ? 1 : 2)


                                    case 0:
                                    Status = "You're dying!";
                                    break;
                                    case 1:
                                    Status = "You're fine!";
                                    break;
                                    case 2:
                                    Status = "You're doing excelent";
                                    break;






                                    share|improve this answer



























                                      0












                                      0








                                      0







                                      I would store the max health in the variable MaxHealth then try the following switch! :)



                                      Here we have if statement in the switch statement, that will do case 1 if the health is between 0 and 20% and so on



                                      double PCHealth = __ ;

                                      switch (((0 <= PCHealth && PCHealth <= (0.2 * MaxHealth)) ? 0 :
                                      ((0.2 * MaxHealth) > PCHealth && (0.5 * MaxHealth) < PCHealth) ? 1 : 2)


                                      case 0:
                                      Status = "You're dying!";
                                      break;
                                      case 1:
                                      Status = "You're fine!";
                                      break;
                                      case 2:
                                      Status = "You're doing excelent";
                                      break;






                                      share|improve this answer















                                      I would store the max health in the variable MaxHealth then try the following switch! :)



                                      Here we have if statement in the switch statement, that will do case 1 if the health is between 0 and 20% and so on



                                      double PCHealth = __ ;

                                      switch (((0 <= PCHealth && PCHealth <= (0.2 * MaxHealth)) ? 0 :
                                      ((0.2 * MaxHealth) > PCHealth && (0.5 * MaxHealth) < PCHealth) ? 1 : 2)


                                      case 0:
                                      Status = "You're dying!";
                                      break;
                                      case 1:
                                      Status = "You're fine!";
                                      break;
                                      case 2:
                                      Status = "You're doing excelent";
                                      break;







                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited Mar 23 at 6:51

























                                      answered Mar 23 at 6:36









                                      StrazanStrazan

                                      53113




                                      53113



























                                          draft saved

                                          draft discarded
















































                                          Thanks for contributing an answer to Stack Overflow!


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid


                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.

                                          To learn more, see our tips on writing great answers.




                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function ()
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55311044%2fhow-can-i-use-percentages-in-a-switch-condition-to-represent-player-status-based%23new-answer', 'question_page');

                                          );

                                          Post as a guest















                                          Required, but never shown





















































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown

































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown







                                          Popular posts from this blog

                                          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                                          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                                          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript