### array help

can someone help me with this,the user suppose to input 5 number but the out come is long different numbers why?

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869`` `````` // Number Sorter #include using namespace std; char menu() { char choice; cout<< "\nNumber Sorter - Created By Ben Tickle"; cout<< "\n\n**************************************\n"; cout<< "\n\n Please choose one of the following:\n"; cout<< "\n\n 1 - Ascending order "; cout<< "\n 2 - Descending order "; cout<< "\n 3 - Exit"; cout<< "\n\n\n**************************************\n"; cout<< "\n\n Enter you choice and press return: "; cin >> choice; return choice; } int main() { int a1,a2,a3,a4,a5; char choice; do { choice = menu(); switch (choice) { case '1': cout << "\n\nAscending order" << "\n\n\nPlease enter 5 numbers include spaces:"; int a[5]; cin >> a1; cin >> a2; cin >> a3; cin >> a4; cin >> a5; for(int i=0;i<5;++i) cout<
on line 46 the output is from the uninitialize/unused array `a` hence no valid numbers
so how can i change it?
 ``383940414243`` `````` int a[5]; cin >> a1; cin >> a2; cin >> a3; cin >> a4; cin >> a5; ``````

 ``3839404142`` `````` cin >> a[0]; cin >> a[1]; cin >> a[2]; cin >> a[3]; cin >> a[4]; ``````

and delete line 24:
 `` `` `` int a1,a2,a3,a4,a5;``

and replace it with
 `` `` `` int a[5];``
Last edited on
thank you it shows the correct numbers now but does not ascend them?
Well, if you want the numbers in a different order, you have to sort them. Either write your own code to do that, or make use of the built-in std::sort.
http://www.cplusplus.com/reference/algorithm/sort/
Topic archived. No new replies allowed.