Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

lgbasallote

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

  • one year ago
  • one year ago

  • This Question is Closed
  1. lgbasallote
    Best Response
    You've already chosen the best response.
    Medals 0

    ////Calculator #include <stdio.h> #include <stdlib.h> #include <windows.h> 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? <Y/N> "); 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; } ```

    • one year ago
  2. snark
    Best Response
    You've already chosen the best response.
    Medals 1

    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...

    • one year ago
  3. lgbasallote
    Best Response
    You've already chosen the best response.
    Medals 0

    hmm so what should i do?

    • one year ago
  4. snark
    Best Response
    You've already chosen the best response.
    Medals 1

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

    • one year ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.