#include <iostream>
#include <cstdlib>

using namespace std;

const int MAX_ARRAY_SIZE = 11;

void instructions();

//Explains the program to user.

void get_integers(int a[],int size);

//Recieves input from user



int main(){
  int numbers[MAX_ARRAY_SIZE];


  instructions();
  get_integers(numbers,MAX_ARRAY_SIZE);
  for(int i = 0;i < MAX_ARRAY_SIZE;i++){

    cout << numbers[i] << " ";
  }



  return 0;


}



void instructions(){

  using namespace std;

  cout <<"\nThis program reads 10 integers from you";
  cout <<"and sorts them from smallest to largest\n";

}

void get_integers( int a[], int size) {
    using namespace std;
    int index;
    int numbers[MAX_ARRAY_SIZE];

    // Use loop-and-a-half to fill array
    cout << "Enter"<< size << "integers: ";
    for(index = 0; index < MAX_ARRAY_SIZE; index++)
      cin >> numbers[index];


}

I'm trying to fill an array of 10 integers for a program that takes in 10 numbers from the user and the program sorts them in ascending order. I don't want to have to prompt every time for the number i want the user to be able to enter in each number by just having a space in between each. My code seems right for handling that but when I run the program it does not do anything when I put in the 10 numbers.. ANY help would be greatly appreciated!

First, you state the problem in terms of 10 numbers for input, but your array and loops are sized for 11.

If you just type in 10 numbers, the for loop is waiting for the 11th!

Also, you pass an array to the get_integers( ) function, but inside it declare another array that you then fill. So, your array in main( ) never gets any input. You should be getting a compiler warning about parameter "a" not being used. Pay attention to the warnings you get - they mean things.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.