Before anything, here's my code:
#include <stdio.h>
#include <conio.h>
#include <math.h>
main()
{
float Exp, Act, Px, Facto_Act;
printf("\n This is Poisson Distribution Calculator!");
printf("\n Enter the expected value of success in a time period:");
scanf("%f",& Exp);
printf("\n Enter the actual or calculated value of success in a time period:");
scanf("%f",& Act);
Px=pow(M_E,-Exp)*pow(Exp,Act)/Facto_Act;
printf("\n Poisson probability is:%f", Px);
getch();
return 0;
}
Facto_Act(float Act)
{
float c;
float result=1;
for(c=1;c<=Act;c++)
result=result*c;
return result;
}
Further explanation:
Poisson equation looks like this:
P(x)= (e^-Lambda)(Lambda^x)/(x!)
Exp: Expected number of events in a given time(Lambda) Act: Actual number of events in a given time(x) Px: Probability of an event occuring in a given time( P(x) ) Facto_Act: Factorial of Actual number of events in a given time(x!)
When I figured out how to do factorials for integer in C, I will try to add factorials for positive decimals too. But #1.INF00 is not a value I expect.
When I compile the code, there are no more coding errors shown. But when I enter the expected value of successes in a period, then the actual value of succesess in a period, I always end up with #1.INF00. I am very noobful of C, and while this site has helped me improved my programs by a bit, I can't understand the '#1.INF00' means.
I decided not to make Facto_Act a function
I decided to circumvent the entire Facto_Act function problem by not making Facto_Act a function, then trying to call it. It seems that factorials can be performed without making a new function for it. Thus Facto_Act is now a variable. This is my new code:
#include <stdio.h>
#include <conio.h>
#include <math.h>
main()
{
double Exp, Px;
int c, Act, Act2, Facto_Act=1;
printf("\n This is Poisson Distribution Calculator!");
printf("\n Enter the expected value of success in a time period:");
scanf("%lf",& Exp);
printf("\n Enter the actual or calculated value of success
\n in a time period(must be an integer!):");
scanf("%d",& Act);
/*My factorial starts here*/
for (c=1;c<=Act;c++)
Facto_Act=Facto_Act*c;
/*My factorial ends here*/
Px=(pow(M_E,-Exp))*(pow(Exp,Act))/Facto_Act;
printf("\n Poisson probability is:%lf", Px);
getch();
return 0;
}
I thank you all for helping me out.