Thread: help me oh gods

  1. #1
    Unregistered
    Guest

    Exclamation help me oh gods

    #include<iostream.h>
    #include<fstream.h>


    float voltage;//assign memory space
    float pressure;



    void main()
    {
    cout<<"Enter the voltage reading: >>>";//get input
    cin>>voltage;

    //convert voltage to pressure

    pressure=((voltage*20)+500);

    if(pressure>=700)
    {
    cout<<"\n*************** WARNING THE PRESSURE IS ABOVE RECOMENDED LEVELS!****************"<<endl;
    }

    /******************** store reading ************************/

    //setup new output stream (call it outfile)

    ofstream outfile;

    //target it to a text file
    //then open it ready for data transfer

    outfile.open("C:\\pressure.txt");

    //send data

    outfile<<pressure<<endl;

    cout<<endl<<"file written\n";

    outfile.close();//do I need this with a write file???


    /********************************/











    cout<<"temp print out of pressure "<<pressure<<endl<<endl;


    }//end main

  2. #2
    Registered User Strider's Avatar
    Join Date
    Aug 2001
    Posts
    149
    outfile.close();//do I need this with a write file???
    Yes. Always close the file after you have made the needed transaction. Even if you require use of the file at some other location within your code, it is always good practice to close it and reopen it for each new purpose.

    David
    One Ring to rule them all, One Ring to find them,
    One Ring to bring them all and in the darkness bind them
    In the Land of Mordor where the Shadows lie.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hey I back home!!!
    By ssharish2005 in forum A Brief History of Cprogramming.com
    Replies: 88
    Last Post: 07-02-2007, 03:11 PM
  2. the language of the gods - C++
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 33
    Last Post: 01-08-2004, 06:00 PM
  3. Religion
    By gnu-ehacks in forum A Brief History of Cprogramming.com
    Replies: 239
    Last Post: 01-26-2002, 10:44 AM
  4. gods gift to programming
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 25
    Last Post: 10-14-2001, 11:11 PM