### Component reliability

I am working on the same question as another member posted here, but I am going about it slightly differently as I see the equation differently.. I can get my program to compile and run, but I run into an issue after I enter in my unsigned int seed. It says that i have not declared "component reliability" even tho I clearly have. What do I seem to be missing here?

Also, under this area: " if (((num1<=component_reliability) &&
((num2<=component_reliability)) &&
(num3<=component_reliability)))", I was considering changing the component reliability to a_parallel considering that is the answer to the equation. I worked out this equation by hand, and it gives me the correct analytical reliability, I just cant seem to get the program to execute it..

Help?!?

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657`` ``````#include #include #include using namespace std; double rand_float(double a, double b); double c; int main() { unsigned int seed; int n; double component_reliability, component_reliability1, component_reliability2, component_reliability3, a_parallel, parallel_success(0), num1, num2, num3; cout << "Enter the indvidual component reliability1: \n"; cin >> component_reliability1; cout << "Enter the indvidual component reliability2: \n"; cin >> component_reliability2; cout << "Enter the indvidual component reliability3: \n"; cin >> component_reliability3; cout << "Enter the number of trials: \n"; cin >> n; cout << "Enter unsigned integer seed: \n"; cin >> seed; srand(seed); cout << endl; a_parallel = (component_reliability1) * (1 - ((1 - component_reliability2) * (1 - component_reliability3))); for (int k=1; k<=n; k++) { num1 = rand_float(0,1); num2 = rand_float(0,1); num3 = rand_float(0,1); if (((num1<=component_reliability) && ((num2<=component_reliability)) && (num3<=component_reliability))) { parallel_success++; } } cout << "Analytical Reliability \n"; cout << "Parallel: " << a_parallel << endl; cout << "Simulation Reliability " << n << " trials \n"; cout << " Parallel: " << (double)parallel_success/n << endl; system ("PAUSE"); return 0; } double rand_float(double a, double b) { return ((double)rand()/RAND_MAX*(b-a) + a); }``````

Last edited on
@zblackbeast

Firstly, please edit your post so it uses code tags - the <> button on the right

You have declared component_reliability, but have not assigned a value to it.

The other thing to be careful about is comparing doubles the way you do. Floating point numbers (floats & doubles etc.) are stored as binary fractions and cannot represent every real number. This why they shouldn't be compared directly. Consider this:

 ``12345`` ``````float a = 0.1; // a == 0.09999997 float b = 10.0 * a; // b == 0.9999997 if(a == b) //false ``````

Changing the type to double doesn't help.

You can make use of `std::numeric_limits<double>epsilon` it needs to be scaled up to the numbers you are using.

Google floating point epsilon to see how to do it correctly.

 http://stackoverflow.com/questions/17333/most-effective-way-for-float-and-double-comparison