### Need help with struc coding

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.
 ``12345678910111213141516171819202122232425262728293031323334353637`` ``````#include #include #include using namespace 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; } ``````

Much Appreciated , if i can get this done.
Last edited on
What do you want to achieve?
In which way does your program behave different to your expectations?
forgot to mention, i am suppose to create a program that computes the binomial coefficient.

the program is suppose to compute binomial coefficient, but i do not have enough info to complete the program.
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).

You may need some math help.

Good luck!
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.
revised
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253`` ``````#include #include #include using namespace std; struct data { int n ; int k ; }; void getinput(data&); void printoutput(data&); void getbinomial_coefficient(data&); int main() { int n,k,binomial; data coef; char flag= 'y'; while(flag=='y') { getinput(coef); getbinomial_coefficient(bc); printoutput(binomial); } 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)); } void printoutput(data&b) { } ``````
It would help you an awful lot if you were to try compiling your program here and there. Start small, add stuff, fix compile errors as they come.

Line 45: there is no member "binomial" in the "data" structure (lines 6-10).

And there shouldn't be. You should make your function return the bc.

 ``1234`` ``````int getbinomial_coefficient(data&bc) { return factorial(bc.n)/(factorial(bc.k)*factorial(bc.n-bc.k)); }``````

Then in main you can say:

 ``1234567891011`` ``````int main() { data coef; int binomial; getinput(coef); binomial=getbinomial_coefficient(coef); printoutput(binomial); return 0; }``````

Add stuff like loops later.

Also, you need to review the concept of "variable scope".

Hope this helps.
but i have getbinomial_coefficient as void. I even have in the header or prototype before main.

here is what i have so far :(made some changes)

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748`` ``````#include #include #include using namespace 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)); }``````

i've got " bc was not declared" error.
 but i have getbinomial_coefficient as void. I even have in the header or prototype before main.

I hope you are trying to tell me that your professor requires this prototype, and not that you are unwilling to do something smart.

The code you just posted won't compile for a number of reasons.
Get rid of line 22 and try again.
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.
Last edited on
I didn't mean to sound mean. Sorry.

What I meant was, I assume that you were required to use

`void getbinomial_coefficient( data & bc )`

`int getbinomial_coefficient( data & bc )`

? Because the first is not a good design.
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?
 ``1234`` ``````for(i=1,i<=j,i++) factorial =factorial*i binomial= ..... ``````

3.expected ';' before 'bc'
i dont know what this means.