Open study

is now brainly

With Brainly you can:

  • Get homework help from millions of students and moderators
  • Learn how to solve problems with step-by-step explanations
  • Share your knowledge and earn points by helping other students
  • Learn anywhere, anytime with the Brainly app!

A community for students.

can someone tell me what's wrong with this? I'll highlight the part I need help with

Computer Science
See more answers at brainly.com
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Join Brainly to access

this expert answer

SIGN UP FOR FREE
////Calculator #include #include #include long factorial(int value); int permutation(int n, int r); int combination(int n, int r); int power(int base, int exponent); void loading(); float binomdist(int n, int r, float p, float q); main() { int menuChoice; int fctrl; int n, r; int base, exp, pow; char yn[2]; float p, q; while (1){ system("cls"); printf("\n Main Menu"); printf("\n =========\n\n"); printf(" <1> Factorial\n"); printf("\n <2> Permutation\n"); printf("\n <3> Combination\n"); printf("\n <4> Power\n"); printf("\n <5> Binomial Distribution\n"); printf("\n\n Enter a number from 1 to 4 > "); scanf("%d", &menuChoice); loading(); system("cls"); if (menuChoice == 1) { printf("\n What number would you like to take the factorial? "); scanf("%d", &fctrl); printf("\n\n Computing...\n"); Sleep(1000); printf("\n\n %d! is %d\n\n\n ", fctrl, factorial(fctrl)); system("pause"); } else if (menuChoice == 2) { printf("\n Enter the value of n > "); scanf("%d", &n); printf("\n Enter the value of r > "); scanf("%d", &r); printf("\n\n Computing...\n"); Sleep(1000); printf("\n\n %dP%d is %d\n\n\n ", n, r, permutation(n,r)); system("pause"); } else if (menuChoice == 3) { printf("\n Enter the value of n > "); scanf("%d", &n); printf("\n Enter the value of r > "); scanf("%d", &r); printf("\n\n Computing...\n"); Sleep(1000); printf("\n\n %dC%d is %d\n\n\n ", n, r, combination(n,r)); system("pause"); } else if (menuChoice == 4) { printf("\n Enter base > "); scanf("%d", &base); printf("\n Enter exponent > "); scanf("%d", &exp); pow = power(base,exp); printf("\n\n Computing...\n"); Sleep(1000); printf("\n\n %d raised to %d is equal to %d\n\n\n ", base, exp, pow); system("pause"); } else if (menuChoice == 5) { printf("\n Enter the number of trials > "); scanf("%d", &n); printf("\n Enter the number of successes > "); scanf("%d", &r); printf("\n Enter the probability of successs in one trial > "); scanf("%f", &p); q = 1 - p; printf("\n\n Computing...\n"); Sleep(1000); printf("\n\n The binomial probability is %f\n\n\n ", binomdist(n, r, p, q)); system("pause"); } else continue; loading(); while (1) { system("cls"); printf("\n Try again? "); scanf("%s", yn); if (yn[0] == 'y' || yn[0] == 'Y') break; else if (yn[0] == 'n' || yn[0] == 'N') return 0; else continue; } loading(); } } long factorial(int value) { long fac; int cntr; fac = 1; for (cntr = 1; cntr <= value; cntr++) fac = fac*cntr; return fac; } int permutation(int n, int r) { int perm; perm = (factorial(n))/(factorial(n-r)); return perm; } int combination(int n, int r) { int comb; comb = (permutation(n,r))/(factorial(r)); return comb; } int power(int base, int exponent) { int pow, cntr; pow = base; for (cntr = 1; cntr < exponent; cntr++) pow = pow*base; return pow; } void loading() { int cntr, ctr; for (cntr = 0; cntr < 3; cntr++) { system("cls"); printf("\n\n\n\n\n\n\n\n\n\t\t\t\t Loading"); for (ctr = 0; ctr < 3; ctr++) { printf("."); Sleep(300); } } } ``` float binomdist(int n, int r, float p, float q) { float bd; int a, b, c; float d; a = combination(n,r); b = power(p, r); c = n - r; d = power(q,c); bd = a * b * d; return bd; } ```
it looks fine - the binomial P(n,r,p) is C(n,r)*pow(p,r)*pow(q,n-r), with q = 1-p. Ah - your power(p,r) returns an int value - power(p,r) must be a float - in fact, power(a,b) takes int arguments - p,q are floats...
hmm so what should i do?

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

float power(float base, int exponent){ float pow = base; for (int i = 1; i < exponent; i++) { pow = base * pow; } return pow; } should work...

Not the answer you are looking for?

Search for more explanations.

Ask your own question