How to print the elements of an array

I have to write a program that order the elements of an array in a specific way. Then, take input values from the user to fill the array and print all the elements of the array. They should all be sorted in ascending order. This is what I have so far, but I am getting errors. (Im new doing this things). I will appreciate any comments. thanks.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include<iostream>
#include<stdlib>

using namespace std;


int main(){
const int N=10;
int values[N];
int count=0;
int k;

  while (count<10){
    cout<<"please enter a number"<<endl;
    cin>>values[count]
    for(int i=N-2; i>0; i--){
      for(int j=0; j<=i; j++){
        if(values[j]>values[j+1]){
          k=values[j];
          values[j]=values[j+1];
          values[j+1]=k;
        }
      }
    }
    cout<<++;
  }
  cout<<values[count]<<endl;
  return 0;
}
You don't need const int N = 10, it will work just fine to have int values[10].

Also your while loop makes an infinite loop because you never modify count, and will always been modifying the first element in the values array.
Topic archived. No new replies allowed.