Q:

Compare user value with value from enum

The essence of the task: to choose the best screen resolution for the user, based on his data.
I need to ompare user value with value from ENUM and return the appropriate one.
For example:
enum class Resolutions {
    V720_height = 720,
    V720_width = 1280,
    V1080_height = 1080,
    V1080_width = 1920
};

int main() {
    int user_height = 1200;
    int user_width = 430;
    // I know this does not work, just an example.
    std::for_each(Resolutions.begin(), Resolutions.end(), [](Resolutions tmp) {
        if (static_cast<int>(tmp) > user_height) {
            std::cout << tmp << " - is better resolution\n";
        }
    });
}

I need a good idea, how can this be implemented?

A:

Using enums is not the best way to do that. I recommend you to use std::map if you need to name the different resolutions.
#include <map>
#include <string>
#include <iostream>

struct Resolution {
    int height;
    int width;
};

const std::map<std::string, Resolution> resolutions = {
    { "V720", {720, 1280} },
    { "V1080", {1080, 1920} }
};

int main() {
    int user_height = 1200;
    int user_width = 430;

     for (auto& [key, value] : resolutions) {
        if (value.height > user_height &&
            value.width > user_width) {
            std::cout << key << " - is better resolution\n";
        }
    }
}

