Extremely confused
I am working on my class final project in which we have to make an array and selection sort, but mine isn't working.
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
#include <iostream>
#include <cmath>
#include <ctime>
using namespace std;
int selectionSort(int [], int);
int main()
{srand (time_t(NULL));
int narray[100];
for (int i=0; i<100; i++){
narray[i]=rand()999;}
}
{
const int NUMEL = narray;
int nums[NUMEL] = {narray[i]};
int i, moves;
moves = selectionSort(nums, NUMEL);
cout <<"The sorted list, in ascending order is: \n";
for (i=0; i < NUMEL; i++)
cout << " " << nums[i];
cout << endl << moves << " moves were made to sort this list. \n";
return 0;
}
int selectionSort(int num[], int numel)
{
int i, j, min, minidx, temp, moves=0;
for (i=0; i<(numel-1); i++)
{
min = num[i];
minidx=i;
for(j = i + 1; j < numel; j++)
{
if (num[j] < min)
{
min = num[j];
minidx = j;
}
}
if (min < num[i])
{
temp = num[i];
num[i] = min;
num[minidx] = temp;
moves++;
}
}
return moves;
}
|
narray[i]=rand()999;}
What is this?
I'm trying to fill an array with 100 psuedo-random numbers but within 0-999 range.
this is the error code im getting on line 12:
error C2447: '{' : missing function header (old-style formal list?)
Topic archived. No new replies allowed.