Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7055023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:41:53+00:00 2026-05-28T03:41:53+00:00

Given a float, how to map it to an enum like {FAIL, POOR, OK,

  • 0

Given a float, how to map it to an enum like

{FAIL, POOR, OK, GOOD, EXCELLENT, PERFECT}

if the divisions aren’t even.

0.0-0.4 is FAIL
0.4-0.6 is POOR
…
0.8-0.999.. is EXCELLENT
1.0 is PERFECT

The float is a rating value calculated from all the played levels in a game. It ranges from 0..1, both inclusive. There are normally no more than about 10 divisions needed, but the spacings are subject to tuning during development.

I’m currently using a stack of if..else statements. Is that the right way to do it? It seems a bit brittle.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:41:54+00:00Added an answer on May 28, 2026 at 3:41 am

    Use an array of structs – either statically allocated or dynamic – and then a simple routine to search it – if its small just iterate, if its large you can do binary search.

    As you know the minimum (0.0) and maximum (1.0) you only need to store the upper-bound of the range and enum value. E.g:

    typedef enum {FAIL, POOR, OK, GOOD, EXCELLENT, PERFECT} Rating;
    
    typedef struct
    {
       float upperBound;
       Rating score;
    } RatingDivision;
    
    static RatingDivision Divisions[] =
    {
       { 0.4, FAIL },
       { 0.6, POOR },
       ...
       { 0.999, EXCELLENT },
       { 1.0, PERFECT }
    };
    

    Now sizeof(Divisions)/sizeof(RatingDivision) will tell you the number of entries (needed for binary search), or just iterate until the value you’re looking for is <= Divisions[i].upperBound returning Divisions[i].score or the upperBound reaches 1.0 with no match and handle the error.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to do an operation like this : if the given float numbers
Given two float matrices in R, I would like to get the relative error
Given a specific DateTime value, how do I display relative time, like: 2 hours
Given an absolute or relative path (in a Unix-like system), I would like to
Given 2 rgb colors and a rectangular area, I'd like to generate a basic
Given the following piece of (pseudo-C++) code: float x=100, a=0.1; unsigned int height =
Given the following code, I would expect it to return float = 32000.0001. But
I have the following two boost::fusion maps. namespace bf = boost::fusion; typedef bf::map<bf::pair<char,float>,bf::pair<int,double>> FusionMap;
Given a float[n] inputdata to pass to the OpenCL kernel, could anyone enlighten me
I want to insert a pair< string, vector<float> > into a map, first it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.