garryhtreez

6.26

Dec 10th, 2020
797
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. /*6.26 Celsius and Fahrenheit Temperatures
  2. F = C * 9/5 + 32
  3. C = (F - 32) * 5 / 9
  4.  
  5. Deitel & Deitel C++ How to Program, 10th ed(Indian subcontinent adaptation)
  6. Visual Studio Community 2019
  7. */
  8.  
  9. #include <iostream>
  10. #include <iomanip>
  11. using namespace std;
  12.  
  13. int main() {
  14.  
  15.     /* Note: Console settings inside VS 2019 Community:
  16.     *     Font: Lucida Console, size 20
  17.     *     Layout: Win width 160 */
  18.  
  19.     // Celsius to Fahrenheit
  20.     for (int i = 1; i <= 5; i++) cout << setw(14) << "Celsius" << setw(14) << "Fahrenheit";
  21.     cout << endl;
  22.  
  23.     int row, col;
  24.     for (row = 0; row <= 20; row++) {
  25.         for (col = 0; col <= 4; col++) {
  26.             if (row + col * 21 > 100) continue;
  27.             cout << setw(14) << row+col*21 << setw(14) << (row + col * 21) * 9 / 5 + 32;
  28.         }
  29.         cout << endl;
  30.     }
  31.  
  32.     cout << endl;
  33.  
  34.     // Fahrenheit to Celsius
  35.     for (int i = 1; i <= 5; i++) cout << setw(14) << "Fahrenheit" << setw(14) << "Celsius";
  36.     cout << endl;
  37.     int fahr;
  38.     for ( row = 0; row <= 36; row++ ) {
  39.         for ( col = 0; col <= 4; col++ ) {
  40.             if( ( row + col * 37 ) + 32 > 212 ) continue;
  41.             fahr = ( row + col * 37 ) + 32;
  42.             cout << setw(14) << fahr << setw(14) << ( fahr - 32 ) * 5 / 9; // don't wrap 5/9 in parens -- expr becomes 0!
  43.         }
  44.         cout << endl;
  45.     }
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment