Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*6.26 Celsius and Fahrenheit Temperatures
- F = C * 9/5 + 32
- C = (F - 32) * 5 / 9
- Deitel & Deitel C++ How to Program, 10th ed(Indian subcontinent adaptation)
- Visual Studio Community 2019
- */
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int main() {
- /* Note: Console settings inside VS 2019 Community:
- * Font: Lucida Console, size 20
- * Layout: Win width 160 */
- // Celsius to Fahrenheit
- for (int i = 1; i <= 5; i++) cout << setw(14) << "Celsius" << setw(14) << "Fahrenheit";
- cout << endl;
- int row, col;
- for (row = 0; row <= 20; row++) {
- for (col = 0; col <= 4; col++) {
- if (row + col * 21 > 100) continue;
- cout << setw(14) << row+col*21 << setw(14) << (row + col * 21) * 9 / 5 + 32;
- }
- cout << endl;
- }
- cout << endl;
- // Fahrenheit to Celsius
- for (int i = 1; i <= 5; i++) cout << setw(14) << "Fahrenheit" << setw(14) << "Celsius";
- cout << endl;
- int fahr;
- for ( row = 0; row <= 36; row++ ) {
- for ( col = 0; col <= 4; col++ ) {
- if( ( row + col * 37 ) + 32 > 212 ) continue;
- fahr = ( row + col * 37 ) + 32;
- cout << setw(14) << fahr << setw(14) << ( fahr - 32 ) * 5 / 9; // don't wrap 5/9 in parens -- expr becomes 0!
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment