The Sorted line of numbers first number is -858993460, then it starts off with the numbers that were input but only displays 9 of them, not the whole 10. Plus the Unsorted shows the numbers sorted now for some reason. I'm about to go crazy because I have no idea why in the world the Unsorted is now showing them sorted, and why the Sorted column is also showing them sorted but is displaying -858993460 as the first number.
Enter 10 Numbers
20
15
33
52
17
64
84
29
44
68
Unsorted Sorted
15 -858993460
17 15
20 17
29 20
33 29
44 33
52 44
64 52
84 64
68 84
Here is my code:
#include <iostream>
using namespace std;
void load_array(int [],int &n);
void sort_array(int [], int);
void print_array(int [], int [], int);
void main()
{
int number[99];
int sort[1];
int n=10;
load_array(number, n);
sort_array(sort,n);
print_array(number,sort,n);
}
void load_array(int a[],int &n)
{
cout<<"Enter 10 Numbers"<<"\n";
for(int b=0; b<n; b++)
{
cin>> a[b];
}
cout<<"\n";
}
void print_array(int number[], int sort[], int n)
{
cout<<"Unsorted"<<" "<<"Sorted"<<"\n";
for(int c=0, d=0; c<n; c++, d++)
{
cout<<number[c]<<" ";
cout<<sort[d]<<"\n";
}
}
void sort_array(int sort[],int n)
{
int temp;
for(int x=0; x<n-1; x++)
{
for(int y=0; y<n-1; y++)
{
if(sort[y]>sort[y+1])
{
temp = sort[y+1];
sort[y+1]=sort[y];
sort[y]=temp;
}
}
}
}
Any help would be greatly appreciated, thanks a lot!
This post has been edited by Chevrolet Fanatic: 28 March 2008 - 09:07 PM

New Topic/Question
Reply




MultiQuote




|