Thread: Help with temperature conversion Chart

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    18

    Help with temperature conversion Chart

    I am working on a temp chart conversion. We have the the conversion from Celsius to Fahreneheit rounded to whole numbers but the conversion from Fahrenheit to Celsius keep putting decimals out. I need it to output whole numbers.
    Here is the code:
    #include <iostream>
    #include <iomanip>
    #include <fstream>
    using namespace std;

    int main()
    {
    ofstream outFile ("ass3.run");
    const int LOWER = 0;
    const int UPPER = 400;
    const int STEP = 10;

    int FARR = LOWER;
    float Celsius;

    /* Print table heading */
    outFile <<setw(19);
    outFile << "Fahrenheit";
    outFile <<setw(12);
    outFile << "Celsius";
    outFile <<setw(20);
    outFile << endl;

    /* print table from LOWER to UPPER */
    for (FARR = LOWER ; FARR <= UPPER ; FARR += STEP)
    {
    int Fahrenheit (int);
    outFile <<setw(15);
    outFile << FARR;
    Celsius = (float(5)/float(9)) * (FARR - 32);
    outFile <<setw(15);
    outFile << Celsius;
    outFile <<setw(15);
    outFile <<endl;
    }
    const int RETARD =0;
    const int STUPID =200;
    const int ASS = 5;

    int CELS = RETARD;
    float FAR;
    outFile <<setw(19);
    outFile <<endl<<endl;
    outFile << "Celsius";
    outFile <<setw(15);
    outFile << "Fahrenheit";
    outFile <<setw(20);
    outFile << endl;

    for (CELS = RETARD; CELS <= STUPID ; CELS += ASS)
    {
    int Celsius (int);
    outFile <<setw(15);
    outFile << CELS;
    FAR = (float(9)/float(5) * (CELS) + 32);
    outFile <<setw(15);
    outFile << FAR;
    outFile <<setw(15);
    outFile <<endl;
    }

    return 0;
    }[CODE]
    This is the output we keep getting:
    Fahrenheit Celsius
    0 -17.7778
    10 -12.2222
    20 -6.66667
    30 -1.11111
    40 4.44444
    50 10
    60 15.5556
    70 21.1111
    80 26.6667
    90 32.2222
    100 37.7778
    110 43.3333
    120 48.8889
    130 54.4444
    140 60
    150 65.5556
    160 71.1111
    170 76.6667
    180 82.2222
    190 87.7778
    200 93.3333
    210 98.8889
    220 104.444
    230 110
    240 115.556
    250 121.111
    260 126.667
    270 132.222
    280 137.778
    290 143.333
    300 148.889
    310 154.444
    320 160
    330 165.556
    340 171.111
    350 176.667
    360 182.222
    370 187.778
    380 193.333
    390 198.889
    400 204.444


    Celsius Fahrenheit
    0 32
    5 41
    10 50
    15 59
    20 68
    25 77
    30 86
    35 95
    40 104
    45 113
    50 122

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Fix the code tags please.

    They go AROUND your code - its not enough just to put [code] in there and hope
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Temperature Conversion code problems
    By eroth88 in forum C Programming
    Replies: 6
    Last Post: 10-22-2006, 01:24 AM
  3. Temperature conversion...
    By Onslaught in forum C Programming
    Replies: 3
    Last Post: 10-21-2005, 01:15 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Header File Question(s)
    By AQWst in forum C++ Programming
    Replies: 10
    Last Post: 12-23-2004, 11:31 PM