I need help with this piece. I have not learned enough of "data structure?", if that's whats it's called.
I manage to get some of it done with some help from my professor. I am still lost.
If you it's not any trouble, tell me how would this be done step by step.
#include <iostream>
#include <cmath>
#include <stdlib.h>
usingnamespace std;
struct data
{
int n ;
int k ;
};
int binomial(int n,int k);
int main()
{
data coef;
char flag= 'y';
while(flag=='y')
{
get_input(coef);
//get_binomial_coefficient(n,k);
print_output(binomial_coefficient);
}
system("pause");
return 0;
}
void get_input(data&coef)
{
cout<< "input value for n ";
cin>>coef.n;
cout<<"input value for k";
cin>>coef.k;
}
Unfortunately, you are lost enough that you need to go see your professor.
You shouldn't actually need a struct in this program.
You are essentially being asked to compute a slice of Pascal's Triangle.
Your program will need a function to compute the factorial of a number.
As well as a function to compute the slice. There is a very good collection of formulas on Wikipedia for calculating (n k).
I probably don't have to , but for the sake of learning it's a must. He is just teaching the principal of it. i know how to calculate the binomial coefficient. I just never done it in code before.
#include <iostream>
#include <cmath>
#include <stdlib.h>
usingnamespace std;
struct data
{
int n ;
int k ;
};
void getinput(data&);
void printoutput(data&);
void getbinomial_coefficient(data&);
int main()
{
data coef;
int binomial;
char flag= 'y';
{
while(flag=='y')
{
getinput(coef);
getbinomial_coefficient(coef);
printoutput(coef);
}
system("pause");
return 0;
}
void getinput(data&coef);
{
cout<< "input value for n ";
cin>>coef.n;
cout<<"input value for k";
cin>>coef.k;
}
void getbinomial_coefficient(data&bc);
{
int binomial,n,k;
bc.binomial=factorial(bc.n)/(factorial(bc.k)*factorial(bc.n-bc.k));
}
not that i was trying to do something smart, i don't think it was required either. He put the format on the board, i just took as a template. So,I assumed it would be void getbinomial_coefficient.
i would assume so that i am suppose to use void getbinomial_coefficient.
When i went ahead to compile and got a few errors.
1. 'struct data' has no member named 'binomial'|
does that mean i need to declare binomial in struct data?
2. 'factorial' was not declared in this scope|
For this would need to use a for loop? like this?