Temperature Unit Conversion

#include <iostream>
using namespace std;
 
// Write your code here
float readTemp(int raw) {
    return raw/10.0f; 
}

float readTemp(int raw, char unit) {
    
    if (unit=='C')
        return raw/10.0f;
    else 
        return (raw/10.0f *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