-
default
is it possible to accept the user pressing return when prompted
to enter a value???
e.g. cout<<"enter the pressure <100>"<<endl;
using this, the user needs only press return to accept the value of 100
/************************************************** ******************
THIS IS MY PRESSURE CONTROL PROGRAM
DESIGNED TO ALERT THE USER TO ANY
PROBLEMS WITH THE PRESSURE.
APPENDS the pressure to a file!!!
ios::app == open file for appending
ios::trunc == delete information in file // say IF entries>12
I would like to add a default (press return) process!!! (how!)
i.e cout<<"pressure reading <100> ";//if user enters return pressure is set to 100
************************************************** ******************/
#include<iostream.h>
#include<fstream.h>
#include<iomanip.h>
float voltage;//assign memory space
float pressure;
float riser1;//used to record whether the temp rises consecutively
float riser2;//
int count;//used to count entries before "ios::trunc" (clearing file)
int rcount;//riser counter
void main()
{
char rnumber[12][2];
char reading[12][5];
ofstream outfile;//setting up stream (called outfile)
outfile.open("C:\\pressure.txt",ios::trunc);//clear existing file before the loop starts
outfile.close();//close it
rcount=0;
riser1=0;//re-setting
riser2=0;//
for(count=0;count<12;count++)//setting counter for loop (12 months)
{//begin for loop1
cout<<"Enter the voltage reading: <"<<voltage<<">";//get input
cin>>voltage;
//if(voltage== )//if voltage == user return
//{
// voltage=voltage;//set voltage to default
//}
//convert voltage to pressure
pressure=((voltage*20)+500);
if(pressure>=700)
{
cout<<"\n\..........************* WARNING THE PRESSURE IS ABOVE RECOMENDED LEVELS!****************"<<endl;
}
riser2=pressure;
if(riser2>riser1)
{
rcount++;
}//end if
else
{
rcount=1;
}
if(rcount>=4)
{
cout<<"\n\..........*********** WARNING! THE LAST "<<rcount<<" ENTRIES HAVE RISEN CONSECUTIVELY *************\n";
//rcount=0;//reset the counter
}//end if
/******************** store reading ************************/
//target stream (outfile) to a text file (pressure.txt)
//then open it ready to append data
outfile.open("C:\\pressure.txt",ios::app);
//send data
if(pressure>=700)//if pressure is >= 700 print asterix's as warning in file
{
outfile<<"***"<<pressure<<"***"<<endl;
}//end if
else//otherwise just print the pressure
{
outfile<<pressure<<endl;
}//end if
cout<<endl<<"file written\n";
outfile.close();//do I need this with a write file???
/********************************/
riser1=riser2;//set riser1 equal to riser2 (helps keep track of the consecutive readings)
cout<<"temp print out of pressure "<<pressure<<endl<<endl;
}//end for loop1
}//end main
-
> is it possible to accept the user pressing return when prompted
to enter a value???
Only if you accept user input as a string.
Here's how it might look
Code:
#include <stdlib.h>
#include <string.h>
int main ( ) {
char buff[100];
float f;
cin.getline( buff, 100 );
if ( strlen(buff) == 0 ) {
f = 100;
} else {
f = atof( buff );
}
return 0;
}
-
of course!
thanks for that
mik