Originally Posted by
whiteflags
Pretty sure that should be
nums2[i] = nums[i];
since nums originally contains all the numbers entered. The variable that is supposed to store the value is supposed to be on the left hand side.
Thanks a ton that got it to compile correctly, now I'm just having trouble getting my sort function to work. The program does compile, but it doesn't sort nums2 at all.
Code:
#include <stdio.h>
# define maxnum 5
void display (int [], int[]);
void bubblesort (int[]);
int main ()
{
int nums [maxnum];
int nums2 [maxnum];
int i;
printf ("Please enter five numbers\n");
for (i=0; i<maxnum; i++){
printf ("Enter a number:");
scanf ("%d", &nums[i]);
nums2[i]=nums[i];
}
printf ("\n");
display (nums, nums2);
system ("PAUSE");
return 0;
}
void display (int nums[], int nums2[])
{
int i;
printf ("Entered List Sorted List\n");
printf ("____________ ___________\n");
for (i=0; i<maxnum; i++){
printf ("%6d %15d\n", nums[i], nums2[i]);
}
printf ("\n\n");
}
void bubblesort (int nums2[])
{
int i, j, temp;
for (i=0; i<(maxnum-1); i++){
for (j=1; j<maxnum; j++){
if (nums2[j]<nums2[j-1])
{
temp=nums2[j];
nums2[j]=nums2[j-1];
nums2[j-1]=temp;
}
}
}
}