I am trying to write an array with user input, read, sort, and print. I have the beginning done, and do not want any help with the rest, what i am looking for is to why my code is returning nothing but 0 for each index.
The zeros are the initial values of the array. Its contents are never changed. However there is an out-of-bounds access to an element which is not part of the array.
You are putting your input into the same array element, the 11th element. Elements 0-9 are uninitialized so you output whatever value was in them when you output your array.
#include <iostream>
constint SIZE = 10; // array size
int numArray[SIZE]; // array
int count, temp; // variable for loops, and bubble sorts
int main()
{
std::cout << "Please enter 10 numbers in any order and i will sort them in ascending\n"
<< "order from lowest to highest\n";
for (count = 0; count < SIZE; count++)
{
std::cin >> numArray[count];
}
std::cout << "\nThis is the list as you have entered it: ";
for(int j = 0; j < SIZE; j++)
{
std::cout << numArray[j] << " ";
}
std::cout << "\n";
}
Please enter 10 numbers in any order and i will sort them in ascending
order from lowest to highest
0 9 1 8 2 7 3 6 4 5
This is the list as you have entered it: 0 9 1 8 2 7 3 6 4 5
We've all been there perkins, all been there. If you have any small questions you don't deem worthy of a post, PM me anytime and I'll see if I can help you out.