How to convert fahrenheit to celsius in C++

3 Answers

0 votes
#include <iostream>
#include <iomanip>

int main()
{
    float f = 1.0, c;
     
    c = (f - 32) / 1.8;
 
    std::cout <<  std::fixed << std::setprecision(2) << f << " Fahrenheit = " << 
                  std::fixed << std::setprecision(2) << c  << " celsius" << "\n";
}



 
/*
run:
 
1.00 Fahrenheit = -17.22 celsius
 
*/

 



answered Feb 19, 2016 by avibootz
edited Jul 22, 2022 by avibootz
0 votes
#include <iostream>
#include <iomanip>

int main()
{
    float f = 1.0, c;
     
    c = (f - 32) * (5.0 / 9.0);
 
    std::cout <<  std::fixed << std::setprecision(2) << f << " fahrenheit = " << 
                  std::fixed << std::setprecision(2) << c  << " celsius" << "\n";
}



 
/*
run:
 
1.00 fahrenheit = -17.22 celsius
 
*/

 



answered Feb 19, 2016 by avibootz
edited Jul 22, 2022 by avibootz
0 votes
#include <iostream>
 
int main() {
     
 int fahrenheit = 96;
       
    double celsius = (fahrenheit - 32) * 5 / 9.0;
       
    std::cout << "Celsius = " << celsius;
}
   
   
   
   
/*
run:
     
Celsius = 35.5556
    
*/

 



answered Jul 22, 2022 by avibootz

Related questions

1 answer 231 views
1 answer 190 views
1 answer 269 views
269 views asked Jul 15, 2021 by avibootz
1 answer 295 views
1 answer 211 views
1 answer 211 views
1 answer 322 views
322 views asked Jul 15, 2021 by avibootz
...