Temperature Unit Conversion

#include <iostream>
using namespace std;
 
// Write your code here
float readTemp(int raw);
float readTemp(int raw,char unit);
 

 float readTemp(int raw){
    return raw*0.1;
 }

 float readTemp(int raw,char unit){
    if(unit=='C'){
        return raw*0.1;
    }
    else if(unit=='F'){
        raw=raw*0.1;
        raw=raw*1.8+32;
        return raw;
    }
    else{
        return 0;
    }
 }
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