# Functions c++

I just started learning functions and I am struggling to solve this. Lecturer gave a hint that you have to start calculating from the bottom aka 256 to the top. This is the code i have so far(its incorrect obviously): EDIT: THIS IS CORRECT CODE: https://code.sololearn.com/cjqthEVDtJPn/#cpp this is the formula(sorry i can only upload as a picture because it would be hard to understand if i would type it all): https://imgur.com/pmJzAFV

11/22/2019 7:56:42 PM

A S16 Answers

New AnswerA S I do not understand how you can divide a floating number by 1 and yet able to get a whole integer.

@CodeCat_ okay, i did. Answer is still incorrect. But can you explain why would i need to use return a;?

A S if the method is of either int, float, char, double or String, it must return a variable. And if the method is of void type, it should directly print using cout.

@Avinesh i dont get your question. User just inputs x, then y is calculated. Y is outputed. Look at the picture i added

A S Your missing some thing here that in the last iteration 'a' storing x*x +0; all previous values are missing... So use float values for a,o so 1st statement of while loop write outside, and take another variable float y; y=x*x+a; And do you know if i input 2 what is output? its better to use functions. better to calculate from top to bottom

Are you trying to do:- 1/((x*x) + 2) / ((x*x) + 4) / ((x*x) + 6) / ((x*x) + 8).....-->/((x*x) + 256) and then divide the total by (x*x)...... using a loop inside a function?

@rodwennejones yes,but you dont have to divide total by x*x because only 256 has to be divided by it

Can you give a sample input..... and an output using that input so I can check my prog does what you need.

the example you gave (input 5, output 120) is simple enough to do in a loop inside a function........but I can't see how the equation in your uploaded image could do that...but i'm no mathematician.

A S What problem you are trying to solve? Give me your Problem in English and Input. I will make you a explained solution in C++

Hello, output, when input 5 is not 120 , sorry for that. And I solved it already, thanks for everybody's help.