Temperature Unit Conversion

#include <iostream>
using namespace std;
 
// Write your code here
float readTemp(int x){
    return x /10.0f;
}
float readTemp(int raw, char unit){
    if (unit == 'C'){
        return raw/ 10.0f;
    }
    if (unit == 'F'){
        return ((raw/10) *1.8 + 32);
    } 
} 
int main() {
    int raw;
    char unit;
    cin >> raw >> unit;
 
    if (unit == 'D') {
        cout << readTemp(raw);
    } else {
        cout << readTemp(raw, unit);
    }
 
    return 0;
}

Solving Approach

 

 

 

 

 


 

Upvote
Downvote
Loading...

Input

250 D

Expected Output

25