Here's my input:
Code:
Enter the number of hours the system is to be used (up to 14): 14
Enter the number of bundle locations (3, 4, 5, or 6): 3
Enter the number of vibration sensors (0, 1, 2, or 3): 0
Enter the number of cameras (2, 3, or 4): 2
Enter the number of sound sensors (1, 2, or 3): 1
On average, the alarm fails once in how many activations? 12341234
Location #1:
Enter the MTTF for camera 1: 10
Enter the MTTF for camera 2: 10
Enter the MTTF for sound sensor 1: 10
Location #2:
Enter the MTTF for camera 1: 10
Enter the MTTF for camera 2: 10
Enter the MTTF for sound sensor 1: 10
Location #3:
Enter the MTTF for camera 1: 10
Enter the MTTF for camera 2: 10
Enter the MTTF for sound sensor 1: 10
Enter the number of tests: 100
Here's my output:
Code:
nsSYS=1
NT=100
RSYS=0.000000
The estimated reliability of this system is: 0.000000
R=0.367879
that RC[2][2] value is always 0.367879 ???
Here's the updated code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <string.h>
void initrand()
{
srand((unsigned)(time(0)));
}
float randfloat();
int irandN(int n);
int irand(int min, int max);
float rel(int HR, int T);
int main()
{
int NT;
int HR;
int NL;
int NV;
int NC;
int NS;
int NA;
int TV;
int TC;
int TS;
int nsV;
int nsC;
int nsS;
int i;
int j;
int k;
int nsLOC;
int nsSYS;
float RSYS;
float RV[10][10];
float RC[10][10];
float RS[10][10];
printf("\n\nEnter the number of hours the system is to be used (up to 14): ");
scanf("%d", &HR);
printf("Enter the number of bundle locations (3, 4, 5, or 6): ");
scanf("%d", &NL);
printf("Enter the number of vibration sensors (0, 1, 2, or 3): ");
scanf("%d", &NV);
printf("Enter the number of cameras (2, 3, or 4): ");
scanf("%d", &NC);
printf("Enter the number of sound sensors (1, 2, or 3): ");
scanf("%d", &NS);
printf("\nOn average, the alarm fails once in how many activations? ");
scanf("%d", &NA);
for(i=1; i<=NL; i++)
{
printf("\n\nLocation #%d: \n", i);
for(j=1; j<=NV; j++)
{
printf("Enter the MTTF for vibration sensor %d: ", j);
scanf("%d", &TV);
RV[i][j] = rel(HR, TV);
}
for(j=1; j<=NC; j++)
{
printf("Enter the MTTF for camera %d: ", j);
scanf("%d", &TC);
RC[i][j] = rel(HR, TC);
}
for(j=1; j<=NS; j++)
{
printf("Enter the MTTF for sound sensor %d: ", j);
scanf("%d", &TS);
RS[i][j] = rel(HR, TS);
}
}
printf("\nEnter the number of tests: ");
scanf("%d", &NT);
RSYS=0;
nsSYS=0;
for(k=1; k<=NT; k++)
{
nsLOC=0;
for(i=1; i<=NL; i++)
{
nsV=0;
for(j=1; j<=NV; j++)
{
if( (randfloat()) < RV[i][j] )
{
nsV = nsV+1;
}
}
printf("%d\n", nsV);
nsC=0;
for(j=1; j<=NC; j++)
{
if( (randfloat()) < RC[i][j] )
{
nsC = nsC+1;
}
}
printf("%d\n", nsC);
nsS=0;
for(j=1; j<=NS; j++)
{
if( (randfloat()) < RS[i][j] )
{
nsS = nsS+1;
}
}
printf("%d\n", nsS);
if( (nsV >= (NV-1)) && (nsC >= 2) && (nsS >= 1) )
{
nsLOC = nsLOC+1;
}
}
printf("%d\n", nsLOC);
if( nsLOC >= (NL-1) )
{
nsSYS = nsSYS+1;
}
}
printf("nsSYS=%d\n", nsSYS);
printf("NT=%d\n", NT);
RSYS = (nsSYS/NT);
printf("\tRSYS=%f\n", RSYS);
printf("\n\nThe estimated reliability of this system is: %f\n\n", RSYS);
printf("\n\tR=%f\n", RC[2][2]);
}
float randfloat()
{
return rand()/((RAND_MAX)+1.0);
}
int irand(int min, int max)
{
static int Init = 0;
int rc;
if(Init == 0)
{
srand(time(NULL));
//void srand(unsigned int seed); //uses same seed for testing
Init = 1;
}
rc = (rand() % (max - min + 1) + min);
return(rc);
}
int irandN(int n)
{
const unsigned range = ((unsigned)(RAND_MAX)+1)/n;
int r;
do r = rand()/range;
while(r >= n);
return(r);
}
float rel(int HR, int T)
{
float R;
R = exp(-HR/T);
return(R);
}
You'll see I changed random number generators