Error Code Mapping

#include <iostream>
#include <cstdint>
using namespace std;

// Declare a scoped enum class ErrorCode : uint8_t
enum class ErrorCode : uint8_t {
    None = 0,
    Timeout = 1,
    Overflow = 2,
    Invalid = 3
};

// Implement: const char* toString(ErrorCode e);
const char* toString(ErrorCode e){
    if(e == ErrorCode::None) 
        return "None";
    else if(e==ErrorCode::Timeout) 
        return "Timeout";
    else if(e==ErrorCode::Overflow) 
        return "Overflow";
    else 
        return "Invalid";
}

int main() {
    int x;
    cin >> x;

    // Input value is guaranteed to be in the range 0&#8211;3
    ErrorCode e = static_cast<ErrorCode>(x);

    cout << toString(e);
    return 0;
}

Solving Approach

 

 

 

 

 

Upvote
Downvote
Loading...

Input

0

Expected Output

None