Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
My roommate's friend knew he needed help with stats/probability. He had no idea he also needed help with his code.
int random;
do
{
random=rand();
} while(random < 1 || random > 100);
//////////////////////////////////////////////////////////////////////
// Title: *removed*
// Programmer: *removed*
// Class: *removed*
// Date: *removed*
/////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int sucess(int percentage); // function declaration
int main(void)
{
int i_count = 0;
int i = 0;
int iteration = 0;
int n = 0;
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int e = 0;
float reliability = 0 ;
float failure = 0 ;
int A = 80;
int B = 75;
int C = 90;
int D = 90;
int E = 70;
FILE *spOut;
int file_close;
spOut=fopen("JKtext.txt","w");
srand(time(NULL));
printf("\n\nHow many times do you want to run? ");
scanf("%d", &n);
//getchar();
iteration = n;
printf("\nRunning iteration %d times", iteration);
for(i=0;i<iteration;i++)
{
a=success(A);
b=success(B);
c=success(C);
d=success(D);
e=success(E);
if((a || b) && d)
i_count++;
else if(c && e)
i_count++;
}
reliability = ((float) i_count/iteration)*100;
failure = 100 - reliability;
printf( "\n====================================================\n");
printf( "==== Circuit Reliability Rate is %.2f%%=============\n", reliability);
printf( "====================================================\n\n");
printf( "*****************************************************\n");
printf( "***** Circuit Failure Rate is %.2f%%******************\n", failure);
printf( "*****************************************************\n");
fprintf(spOut, "%.2f\n", reliability);
fprintf(spOut, "%.2f\n", failure);
file_close = fclose(spOut);
printf("\nA text file has been produced. ");
return 0;
}
//FUNCTIONS
int success(int percentage)
{
int random;
do
{
random=rand();
} while(random < 1 || random > 100);
if(random > percentage)
{
return 0;
}
else
{
return 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.