C++ help

Discussion in 'OT Technology' started by Stemby, Sep 19, 2005.

  1. Stemby

    Stemby Whoooose House? COOOOOOOOOOOOGS HOUSE!

    Joined:
    Sep 16, 2004
    Messages:
    3,465
    Likes Received:
    0
    Location:
    Houston,Tx
    i need to display 2 colums in C++ in a text file the right colum needs to have + and the left needs nothing. the numbers are comming out of a double


    Exmple

    left right
    1 -1
    2 -4
    3 -19


    Code:
    #include <iostream>
    #include <fstream>
    #include <iomanip>
    using namespace std;
    int main()
    {
            double c=0;  //set varible
            ofstream datafile;
            datafile.open("output.txt", ios::out);    //open file to write to
            datafile << "Fahrenheit        Celsius"<< endl; //set colums up
            datafile << ios::fixed << setprecision( 3 );
            for(int f=0;f<=212;f++)
            {
                    c= (5.0/9.0)*(f-32); //calulations
                    //format the Tempature
                    datafile << setw( 10 ) << f << setw( 15 )<< ios::showpos<< c << endl;
                 
            }
        datafile.close();
            return 0;
    }
    
     

Share This Page