Using MS Visual C++ 6.0 after making the changes suggested it seems to work fine for me.
Code:
/**************************************************
******************
THIS IS MY PRESSURE CONTROL PROGRAM
DESIGNED TO ALERT THE USER TO ANY
PROBLEMS WITH THE PRESSURE READINGS.
ERASES the existing information in a file,
then APPENDS the pressure to that file!!!
ios::trunc == delete information in file // say IF entries>12
ios::app == open file for appending
**************************************************
******************/
#include<iostream.h>
#include<fstream.h>
#include<iomanip.h>
#include <time.h>
#include <conio.h>
#define WARNING 1
#define OK 0
int index;//acts as counter for pressure array
float riser1;//used to count the number of consecutively rising readings
float riser2;//
int rcount;//riser counter also used
float amount;//amount above recomended level
void main()
{
float voltage[12];
float pressure[12];
int status[12] = {0};
ofstream outfile;//setting up stream (called outfile)
outfile.open("C:\\pressure.txt",ios::trunc);//clear existing file BEFORE the loop starts
outfile<<"TEXT FILE WRITTEN BY MICHAEL MCGUIRE TO DISPLAY PRESSURE READINGS\n\n";
outfile.close();//close it!!!
riser1=0;//set riser1 to 0
riser2=0;//set riser2 to 0
rcount=0;//set rcount to
for(index=0;index<12;index++)//setting counter for loop (12 months)
{//begin for loop1
cout<<"\nEnter the voltage for reading number: "<<index+1<<" >> ";//prompt for input
cin>>voltage[index];//input voltage
pressure[index]=((voltage[index]*20)+500);//convert to pressure
amount=(pressure[index]-700);//set amount to 700 minus pressure
if(pressure[index]>=700)//if equal to or greater than print this to screen
{
cout<<endl<<endl<<endl<<endl<<endl<<endl<<"\n\..........********* WARNING THE PRESSURE IS "<<amount<<" ABOVE RECOMENDED LEVELS!***********"<<endl;
}
//target stream (outfile) to a text file (pressure.txt)
//then open it ready to APPEND data
outfile.open("C:\\pressure.txt",ios::app);//open to append
//send data
if(pressure[index]>=700)//if pressure is >= 700 print asterix's as warning in file
{
outfile<<"*** "<<pressure[index]<<" *** THIS IS "<<amount<<" ABOVE MAXIMUM ALLOWED TEMPERATURE"<<endl;
}//end if
else//otherwise just print the pressure
{
outfile<<pressure[index]<<endl;//remembering to change line
}//end if
outfile.close();//close file
if(pressure[index]>=700)
{
status[index]=WARNING;
}//end if
else
{
status[index]=OK;
}//end else
riser2=pressure[index];//set riser2 to pressure,
if(riser2>riser1)//now if riser2 is greater than riser1
{
rcount++;//add one to the counter (keeping count of consecutively rising readings)
}//end if
else
{
rcount=1;//else give counter value of 1
}
if(rcount>=4)//if counter is greater than or equal to 4 (consecutively risen readings)
{
cout<<"\n\..........*********** WARNING! THE LAST "<<rcount<<" ENTRIES HAVE RISEN CONSECUTIVELY ************\n";//alert
cout<<"\n**** TRY RELEASING SOME OF THE PRESSURE FROM THE MAIN TANK USING THE VALVE ****\n";
//the user to how many consecutive rises there has been
}//end if
cout<<endl<<"file written\n\n\n";//inform the user the file has been written
riser1=riser2;//set riser1 to riser2
}//end loop1
cout<<setw(5)<<"readings"<<setw(12)<<"pressure"<<setw(18)<<"status"<<endl;//setting column width
for(index=0;index<12;index++)//12 times
{
cout<<setw(5)<<index+1<<setw(12)<<pressure[index];
if (status[index] == OK)
cout << setw(20) << "OK" << endl;
else
cout << setw(20) << "WARNING" << endl;
}//end for
time_t hold_time;
hold_time=time(NULL);
outfile.open("C:\\pressure.txt",ios::app);//open to append
outfile<<"\nThis file was modified on: "<<ctime(&hold_time);
outfile.close();
}//end program
David