Question: A program that reads the values from a file containing carbon monoxide detector readings in ppm, counts the number of values, and stores the toxic
A program that reads the values from a file containing carbon monoxide detector readings in ppm, counts the number of values, and stores the toxic level values in a file. The values are listed below, but the program should be able to process a file that contains any number of values. Do not store the values in an array. Instead, read a value, store it in a variable, process it, then read the next value, storing it in the same variable. Loop through the file in this manner. Carbon monoxide that is higher than 35ppm is considered to be toxic by the OHSA. Output all toxic values to a file called toxicCO.txt. Output to the console, the total number of readings and the total number of toxic readings.
below is my code.... but something wrong with it....
#include
#include
#include
using namespace std;
int main()
{
int num = 0, count = 0, CO = 0;
ifstream inputF;
ofstream outputF;
inputF.open("Data.txt");
outputF.open("toxicCO.txt");
if (inputF)
{
cout << "the carbon monoxide readings are: ";
while (!inputF.eof())
{
inputF >> num;
cout << num << endl;
if (num > 35)
{
count++;
outputF << num << endl;
}
inputF >> num;
CO++;
}
cout << endl;
cout<< "There are " << CO<<" stored carbon monoxide data " << endl;
}
cout << "the carbon monoxide that are in toxic levels are: ";
for (int i = 0; i <= count; i++)
{
outputF << num;
cout << num << ", ";
}
cout << "the number of toxic readings is " << count + 1 << endl;
inputF.close();
outputF.close();
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
