Process Sensor Reading

#include <iostream>
using namespace std;
// Write your two overloaded process() functions here
void process(int& x){
    if(x>=0){
        x=x*2;
        
        
    }
   
}
void process(const int& x){
    if(x<0){
        
        cout<<"readonly";
    }
}
int main() {
    int x;
    std::cin >> x;

    if (x < 0) {
        process(static_cast<const int&>(x));   // call read-only overload
    } else {
        process(x);                            // call modifying overload
        std::cout << x;
    }

    return 0;
}

Solving Approach

 

 

 

 

 

Upvote
Downvote
Loading...

Input

5

Expected Output

10