Converting Fahrenheit to Celsius from 0 to 212 degrees to floating-point Celsius temperatures with 3 digits of precision. - C++ File Stream

C++ examples for File Stream:cout

Introduction

Use the formula

celsius = 5.0 / 9.0 * ( fahrenheit - 32 ); 

Demo Code

#include <iomanip>
#include <iostream>

int main(int argc, const char *argv[]) {
    std::cout << std::right << std::setw(12) << "Fahrenheit" << std::setw(12) << "Celsuis" << std::endl;

    for (int i = 0; i <= 212; ++i) {
        std::cout << std::right << std::setw(12) << i << std::right
                  << std::setw(12) << std::setprecision(3) << std::showpos
                  << std::fixed << ((5.0 / 9.0) * (i - 32)) << std::endl;
    }/*from   w w w.j ava2  s .c  om*/

    return 0;
}

Result


Related Tutorials