Originally posted by romeoz
I was reading over all these codes given on here and checking in my textbook and I dont understanf what y; does and float z;, I'm really lost, could you maybe explain that a little more into detail. I have never even seen this until now and I dont know where to start let alone what that code means that you wrote to help me out. sorry about that.
Here you go, an explanation:
Code:
float p(int i) // take an int, return a float
{
if( i < 10 && i > 1 ) //check boundaries
{
// declare 2 integers, x and y
int x = i*i,
y;
// declare a floating point number
float z;
// make a loop, use y as the loop
// counter to move through it.
// something like:
for( y = ... ; ... ; ... )
// do stuff here
// you have to use a float to store
// the sum, since you're returning
// a decimal value
return z / (float)x;
}
return 1.0;
}
I left the loop itself out intentionally, since you provided on effort of your own, only what you needed done. The loop was left out so you could learn how to do it on your own.
Not that that matter, since not matter what your question, some one will do the work for you. It always works that way.
Quzah.