Ok, so I have to calculate the reliability of the circuit below (sorry, the picture is somewhat crude). It doesn't really matter if you look at it that much because it is explained below:
http://img110.imageshack.us/img110/6769/reliabfi3.jpg
Anyways, I already created this program to find the reliability of x number of circuits:
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a, b, c, d, e;
double s;
double t;
double r;
int num;
printf("Enter the number of circuits you want to test: ");
scanf("%d", &num);
fflush(stdin);
for (t=0; t<num; t++) // loop for number of trials
{
r = rand()%100; // reliability of circuit
if (r > 20) //reliability of a
{
a = 1;
}
else
a = 0;
r = rand()%100;
if (r > 25) //reliability of b
{
b = 1;
}
else
b = 0;
r = rand()%100;
if (r > 10) //reliability of c
{
c = 1;
}
else
c = 0;
r = rand()%100;
if (r > 10) //reliability of d
{
d = 1;
}
else
d = 0;
r = rand()%100;
if (r > 30) //reliability of e
{
e = 1;
}
else
e = 0;
{
if (a+d==2||b+d==2||c+e==2) // computes number of successes
{
s = s + 1;
}
}
}
printf("The reliability of the circuit is: %f%%\n", ((s/t)*100));
return(0);
}
Now, I need to write a program that calculates the theoretical (mathematical) reliability of the circuit. Here is what I have so far, but I am stuck and I'm not sure what to do next. In my .txt file I have set:
0-.80
1-.75
2-.90
3-.90
4-.70
Again, I need to calculate the expected reliability of the circuit. The cost is a different part, but I don't need help with that right now, so it can be ignored for now... Anyways, the mathematical reliability of the circuit is 94.635%. To calculate this, you know that 95% will get through A or B, and 90% of those will get through D, or 85.5% through the top part of the circuit. The probability of something getting through the bottom part is 63%. To calculate the failure, you take the probability of the top failing times the probability of the bottom failing. .145 x .37 = .05635 is the chance of failing. 1 - failure = success = .94635.
So basically I need some help figuring out how to make the program do this. I'm new to structs and don't understand them very much, some guidance with the coding would be greatly appreciated.
Here is what I have so far:
Code:
#include <stdio.h>
#include <stdlib.h>
#define NUMBER_OF_CIRCUITS 5
int main()
{
double a, b, c, d, e;
typedef struct{
char name;
double reliability;
double cost;
} circuit;
enum components {a = 0, b = 1, c = 2, d = 3, e = 4};
for(i = 0; i < NUMBER_OF_CIRCUITS; i++)
circuits[i].count = 0;
inputFile = fopen("circuitreliability.txt", "r");
return (0);
}
TIA for any help.