Skip to content

Instantly share code, notes, and snippets.

@NonLogicalDev
Created December 4, 2012 07:40
Show Gist options
  • Save NonLogicalDev/4201590 to your computer and use it in GitHub Desktop.
Save NonLogicalDev/4201590 to your computer and use it in GitHub Desktop.
Negative pressure Unit Calculator (revised)
/**
* Calculate the amount of Negative pressure needed for a given size of an enclosed area.
* @authr Phoenix560.
* November 2012
*/
#include <iostream>
#include <cmath>
using namespace std;
bool sanitiseIO( istream& stream ) {
bool badStream = false;
if ( stream.fail() ) badStream = true, cin.ignore(1000,'\n');
cin.clear();
return badStream;
}
template <typename type>
type getValueIfGreaterThanZero( istream& in , ostream& out ) {
type result;
while (true) {
in >> result;
sanitiseIO(cin);
if( result > 0 ) break;
else
out << "must have a value higher than 0! " << endl;
}
return result;
}
int main()
{
// variables for the option of Units
char units;
// Start with unit conversion from cubic metres to cubic feet.
// Variables for Length, Width and height.
float length, width, height;
// Variables for cubic metres, cubic feet and air changes
float cubicfeet, cubicmetres, answer;
int airchanges;
//request user input for Measurement Units
cout << "Please enter units ('F' for Feet OR 'M' for Metres): " << flush;
for(bool success = false; !success; )
{
cin >> units;
sanitiseIO(cin);
// I FRIGGIN MISS RUBY BLOCKS RIGHT HERE... *"'>_<'"*
// I can't make it smaller without making it bigger somewhere else and more
// mindfucking... That's the C++ paradox...
switch (units) {
case 'M':
case 'F':
success = true;
break;
default:
cout << "Must be either feet ('F') Or Metres ('M')" << endl;
break;
}
}
// deturmine the length of the area in metres and validate user input
cout << "Please enter the Length of the area: " << flush;
length = getValueIfGreaterThanZero<float>(cin,cout);
// deturmine the height of the area in metres and validate user input
cout << "Please enter the Width of the area: " << flush;
width = getValueIfGreaterThanZero<float>(cin,cout);
// deturmine the height of the area in metres and validate user input
cout << "Please enter the Height of the area: " << flush;
height = getValueIfGreaterThanZero<float>(cin,cout);
//determine amount of air changes and validate user input
cout << "Please enter the required amount of air changes (Minimum of 8): " << flush;
airchanges = getValueIfGreaterThanZero<int>(cin,cout);
//Run calculation
if(units == 'F') {
cubicfeet = ((length * width) * height);
answer = (cubicfeet * airchanges) / 60;
cout << "\nThe result is (answer) " << (double)answer << "cfm" << endl << endl;
}
else if(units == 'M') {
cubicmetres = (length * width) * height;
cubicfeet = cubicmetres * 3.2808399;
answer = (cubicfeet * airchanges) / 60;
cout << "\nThe result is " << (double)answer << "cfm" << endl << endl;
}
else {
cout << "error" << endl;
}
// Sugest NPU sizes:
// (Try to fugure out a more generic way to do this)
// (as in, try to use formula or what not, and substutute placeholders in the answer)
// (I'd take a stab at this, but I have no bloody clue what this thing is doing)
if(answer <= 500)
cout << "You need a 500cfm Negative Perssure unit! " << endl;
else if ((answer > 500) && (answer <= 850))
cout << "You need 1 x 850 Or 2 x 500cfm Or, 1x 1500cfm! " << endl;
else if ((answer > 850) && (answer <= 1000))
cout << "You need 2 x 500cfm Or, 1x 1500cfm! " << endl;
else if ((answer > 1000) && (answer <= 1500))
cout << "You need a 1500cfm Negative pressure unit! " << endl;
else if ((answer > 1500) && (answer <= 2000))
cout << "You need 1 x 1500cfm and 1 x 500cfm OR," << endl,
cout << "1 x 2000cfm Negative pressure unit! " << endl;
else if ((answer > 2000) && (answer <= 3000))
cout << "You need 2 x 1500cfm Negative pressure units! " << endl;
else if ((answer > 3000) && (answer <= 4000))
cout << "You need 2 x 2000cfm OR, 1 x 4000cfm Negative pressure unit!" << endl;
else if ((answer > 4000) && (answer <= 4500))
cout << "You need 1 x 4000cfm and 1 x 500cfm Negative pressure units! " << endl;
else if ((answer > 4500) && (answer <= 5500))
cout << "You need 1 x 4000cfm and 1 x 1500cfm Negative pressure units! " << endl;
else if ((answer > 5500) && (answer <= 6000))
cout << "You need 1 x 4000cfm and 1 x 2000cfm Negative pressure units! " << endl;
else if ((answer > 6000) && (answer <= 8000))
cout << "You need 2 x 4000cfm Negative pressure units! " << endl;
else
cout << "Answer unknown, error?\n\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment