return type function and counters
in
Programming Questions
•
1 year ago
hi,
as a part of a project i've written a return type function to return a minimum number from a continuing string of numbers received. the function should return a minimum value for each collection of numbers it is sent (per frameNum). it seems like it should be straight forward, but i am getting nothing but '0' as my return value. i've checked to see if the numbers are being appended to array; they are. but, i noticed that my counter, which keeps track of that process never exceeds 1. while that is a problem in itself, even though the counter never exceeds '1,' the program seems to enter the following conditional statement; it shouldn't. if my counter never exceeds 1, i don't see how it can be >= my maxNum value. however, when i use println statements to check what's going on within the conditional, it's printing my queries.
the two days i've spent seems way too long to write min value function. maybe i've been looking at it too long.
does anyone see what's going on with this function?:
//declared variables
int minNumCounter = 0
int frameNum = 0;
int numFrames = 8;
int maxNums = 200;
//function call
minReturnFunc(streamOfValues);
//function
int minReturnFunc(int sentValue)
{
Array[minNumCounter] = sentValue;
minNumCounter ++; //doesn't increment above 1
if(minNumCounter >= maxNum);
{
minArrayVal = Array[0];
for(int i = 0; i <= Array.length - 1; i ++)
{
if(Array[i] <= minArrayVal)
{
minArrayVal = Array[i];
if(i == (Array.length - 1))
{
println(frameNum); //skips indices?? getting 0, 2, 4, 6
frameNum ++;
minNumCounter = 0;
if(frameNum >= (numFrames - 1))
{
frameNum = 0;
exit();
}
return minArrayVal;
}
}
}
}
return 0;
}
thanks,
destro.
as a part of a project i've written a return type function to return a minimum number from a continuing string of numbers received. the function should return a minimum value for each collection of numbers it is sent (per frameNum). it seems like it should be straight forward, but i am getting nothing but '0' as my return value. i've checked to see if the numbers are being appended to array; they are. but, i noticed that my counter, which keeps track of that process never exceeds 1. while that is a problem in itself, even though the counter never exceeds '1,' the program seems to enter the following conditional statement; it shouldn't. if my counter never exceeds 1, i don't see how it can be >= my maxNum value. however, when i use println statements to check what's going on within the conditional, it's printing my queries.
the two days i've spent seems way too long to write min value function. maybe i've been looking at it too long.
does anyone see what's going on with this function?:
//declared variables
int minNumCounter = 0
int frameNum = 0;
int numFrames = 8;
int maxNums = 200;
//function call
minReturnFunc(streamOfValues);
//function
int minReturnFunc(int sentValue)
{
Array[minNumCounter] = sentValue;
minNumCounter ++; //doesn't increment above 1
if(minNumCounter >= maxNum);
{
minArrayVal = Array[0];
for(int i = 0; i <= Array.length - 1; i ++)
{
if(Array[i] <= minArrayVal)
{
minArrayVal = Array[i];
if(i == (Array.length - 1))
{
println(frameNum); //skips indices?? getting 0, 2, 4, 6
frameNum ++;
minNumCounter = 0;
if(frameNum >= (numFrames - 1))
{
frameNum = 0;
exit();
}
return minArrayVal;
}
}
}
}
return 0;
}
thanks,
destro.
1