I wrote a program that accepts user input for numbers that are placed into an ar
ID: 3619844 • Letter: I
Question
I wrote a program that accepts user input for numbers that are placed into an array. I wrote functions to return the arrays contents and the smallest number the user input into the array. All that code works fine. I can't figure out how to not only return the smallest number in the array, but the subscript of the smallest number in the array. I took a crack at it but I'm returning the SIZE of the array, rather than the smallest number index the array. Can someone help? (I've pasted the code for the function to return the smallest number and smallest number's index in array ONLY)"void smallestNumber(int lowest, int numbersArray[], int count, int size, int lowestIndex)
{
lowest = numbersArray[0];
for (count = 1; count < size; count++)
{
if (numbersArray[count] < lowest)
lowest = numbersArray[count];
}
cout << " The smallest number in the array is " << lowest << endl; // print smallest number in array
cout << " The smallest number's subscript (also known as index) is: " << count << endl; // print the index of the smallest number in array
}
Explanation / Answer
void smallestNumber(int lowest, int numbersArray[], int count, int size, int lowestIndex) { lowest = numbersArray[0]; lowestIndex = 0; for (count = 1; countRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.