I am trying to get the array location to print out along with the value that is stored in that array. It works in a list of the printout of the array & value but does not later when I am trying to use it in a cout of a high and low search.
The array size is 10 so address 0-9 are relevant and contain the data (int) entered. But when searched for high and low in the array the high returns correctly in the cout but then the array address (location) jumps to 10 and the low comes back as a 0 even when that is incorrect also at address 10 (which has no value entered and may well be 0)
Here is the example
for ( int j = 0; j < arraySize; j++ )
cout<< setw( 7 ) << j << setw( 13 ) << nums[j] << endl;
for ( j=0; j<arraySize; j++)
cout<<nums[j]<<" "<< j<<'\n';
//above it works just fine 0-9 with all the right values in place
//but below j becomes 10 and only the high is correct
for (j=0; j<arraySize; j++)
if (nums[j] > high)
high=nums[j];
else
high=high;
for (int u=0; u<arraySize; u++)
if (nums[j] < high)
low=nums[j];
else
low=low;
cout<<"The Highest Number is : "<<high<<" At Array Position: "<<j<< '\n';
cout<<"The Lowest Number is : "<<low<<" At Array Position: "<<j<< '\n';
The array size is 10 so address 0-9 are relevant and contain the data (int) entered. But when searched for high and low in the array the high returns correctly in the cout but then the array address (location) jumps to 10 and the low comes back as a 0 even when that is incorrect also at address 10 (which has no value entered and may well be 0)
Here is the example
for ( int j = 0; j < arraySize; j++ )
cout<< setw( 7 ) << j << setw( 13 ) << nums[j] << endl;
for ( j=0; j<arraySize; j++)
cout<<nums[j]<<" "<< j<<'\n';
//above it works just fine 0-9 with all the right values in place
//but below j becomes 10 and only the high is correct
for (j=0; j<arraySize; j++)
if (nums[j] > high)
high=nums[j];
else
high=high;
for (int u=0; u<arraySize; u++)
if (nums[j] < high)
low=nums[j];
else
low=low;
cout<<"The Highest Number is : "<<high<<" At Array Position: "<<j<< '\n';
cout<<"The Lowest Number is : "<<low<<" At Array Position: "<<j<< '\n';
Comment