HI I can't quite seem to figure out how to code this please help :)
When assessing the quality of indoor air in office buildings, three types of pollutants are of con- cern; Total Volatile Organic Chemicals (TVOC), Polar Volatile Organic Chemicals (PVOC), and Respirable Particulate Matter (RPM). If all of the TVOC, PVOC, and RPM levels are below 300, 120, 60 μg/m3, respectively, the air quality is considered to be acceptable. If any of the TVOC, PVOC, and RPM levels are in excess of 500, 200, or 90 μg/m3, respectively, the air quality is considered to be unacceptable. Otherwise the air quality is considered to be marginal.
Write a computer program, air.c, which reads the concentrations of TVOC, PVOC, and RPM from the keyboard and reports the air quality to an output file.
For marking purposes, run your program 3 times using the values shown in the following table, and report the results for all three runs.
TVOC PVOC RPM
----------------------------------
245 113 60
419 236 80
119 105 52
Sample output is as follows;
TVOC concentration = 580 PVOC concentration = 60 RPM concentration = 130 Air quality is unacceptable.
Answer
Code
#include <stdio.h>
#include <stdlib.h>
int main(){
int tvoc,pvoc,rpm; //variables to
represent pollutants
FILE *fp; //pointer to file
printf("Enter the concentration of TVOC pollutant:
"); //display the message
scanf("%d",&tvoc); //read the
concentration of TVOC from the keyboard
printf("Enter the concentration of PVOC pollutant:
"); //display the message
scanf("%d",&pvoc); //read the
concentration of PVOC from the keyboard
printf("Enter the concentration of RPM pollutant:
"); //display the message
scanf("%d",&rpm); //read the
concentration of RPM from the keyboard
fp = fopen("output.txt","a+"); //open the
file
/* exit the program if file pointer returns null
*/
if(fp == NULL){
printf("Error!");
exit(1);
}
/* If all of the TVOC, PVOC, and RPM levels are
below
300, 120, 60 µg/m3, the air quality is acceptable.
*/
if((tvoc < 300) && (pvoc < 120)
&& (rpm < 60)){
fprintf(fp, "TVOC concentration =
%d\n", tvoc); //write the TVOC concentration to the
file
fprintf(fp, "PVOC concentration =
%d\n", pvoc); //write the PVOC concentration to the
file
fprintf(fp, "RPM concentration =
%d\n", rpm); //write the RPM concentration to the
file
fprintf(fp, "Air quality is
acceptable.\n\n"); //write message to the file
}
/* If any of the TVOC, PVOC, and RPM levels are in
excess of
500, 200, or 90 µg/m3, the air quality is
unacceptable. */
else if((tvoc > 500) || (pvoc > 200) || (rpm
> 90)){
fprintf(fp, "TVOC concentration =
%d\n", tvoc); //write the TVOC concentration to the
file
fprintf(fp, "PVOC concentration =
%d\n", pvoc); //write the PVOC concentration to the
file
fprintf(fp, "RPM concentration =
%d\n", rpm); //write the RPM concentration to the
file
fprintf(fp, "Air quality is
unacceptable.\n\n"); //write message to the file
}
else{
fprintf(fp, "TVOC concentration =
%d\n", tvoc); //write the TVOC concentration to the
file
fprintf(fp, "PVOC concentration =
%d\n", pvoc); //write the PVOC concentration to the
file
fprintf(fp, "RPM concentration =
%d\n", rpm); //write the RPM concentration to the
file
fprintf(fp, "Air quality is
marginal.\n\n"); //write message to the file
}
fclose(fp); //close the
file
return 0;
}
Code Screenshots


Sample Output after First Run


Sample Output after Second Run


Sample Output after Third Run


Note - Please comment for any query.
HI I can't quite seem to figure out how to code this please help :) When...