Hi all, i have a certain question.
Why that doesnt work?It gives zeros for min and max always.If i dont define them as zeros, there appear numbers like min - 4327867324 max - 1265764324
1 2 3 4 5 6 7
int min=0;
int max=0;
...
...
...
if (funct<min) funct=min;
if (funct>max) funct=max;
??
I looked at the topics here and in another forums, but i cant find an answer.
If you create a variable, and don't give it a value, it will have whatever value was in the memory space. Could be anything. Look up "uninitialised variable".
There is nothing special about making an int called min. It won't magically have a very low value. You have to set the value yourself. There are functions available that will give you the lowest possible number that a type can represent, and sometimes macros that are hard-coded with low values, but you still have to create the variable and set the value.
I want to do this, but it doesnt works.When i define min as zero up there and after that - if (funct<min) funct=min, in the screen appears only "min value of the function is zero.Max- zero".
PanGalactic, I want to appear the min and max values of the function.
No, i want to make it so the program outputs the min and max of a function.
for example, the function is 1-x+2.
And the x changes every time.The min and max should be the minimum and maximum value of the function
A final thought; what happens if you start by setting min to equal zero, and in the program the real min is actually, say, 5? The min will be reported as zero, but it was actually five. THis is bad.
There is something simple you can do to ensure this never happens (and similarly if you set max to zero, but in the function it is always actually lower than that), but I'll leave that to you to think about.