can anyone please check this program to see what's wrong on it .

i" am taking c++ class now and I am strugling with that problem.

here is the part i have problem with

Program will put the numbers in order and print the sorted list. First in the incremental, later in the decremented order.

so when i trying to print the sorted list in decremental and decremented order i cant get it. he keeps giving me the same number. please can someone gives an idea

#include <iostream>
#include<stdio.h>
#include<conio.h>


using namespace std;

int main()
{
int i,n, j, x, y;
double number [10] = {};


cout << "how many number do you want to key in?" << endl;
cin >> n ;

for (i=0; i<n; ++i )
{
cout <<"enter your numbers:"<< endl;
cin >> number [n];
}
for (i=0;i<n;++i)
{
for (j=1;j<n;++j)
{
if (number[i]>number[j])
{
x=number[i];
number[i]=number[j];
number[j]=x;
}
}
}
cout << "Here is the incremental order of your number :" << x << endl;
cin.get ();

for (i=0;i<n;++i)
{
for (j=i+1;j<n;++j)
{
if (number[i]< number[j])
{
y=number[j];
number[j]=number[i];
number[i]=y;
}
}
}
cout << " here is the decremented order of your given numbers:" << y << endl;

cin.ignore ();
cin.get ();
return 0;
}

I think you've got a misprint here:
1
2
3
4
5
for (i=0; i<n; ++i )
 {
 cout <<"enter your numbers:"<< endl;
 cin >> number [n];
 }


You must have intended to write "number[i]" instead of "number[n]"
Topic archived. No new replies allowed.