Sensor Filter Selection

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

// Write your enum and function here
enum FilterMode{
    NONE, 
    LOW, 
    HIGH
};

int readSensor(int raw, FilterMode mode = NONE) {
    if (mode == NONE) {
        return raw; 
    }
    if (mode == LOW) {
        return raw/2; 
    }
    return raw/4; 
}

int main() {
    int raw, modeFlag;
    cin >> raw >> modeFlag;

    if (modeFlag == 0) {
        cout << readSensor(raw);
    } else {
        string filterName;
        cin >> filterName;

        FilterMode filter;

        if (filterName == "LOW") {
            filter = LOW;
        } else {
            filter = HIGH;
        }

        cout << readSensor(raw, filter);
    }

    return 0;
}

Solving Approach

 

 

 

 

Upvote
Downvote
Loading...

Input

100 0

Expected Output

100