Please help

Ok so I have no idea what i'm doing wrong but it seems that every time i program i always get unresolved external errors. Last time it was because I only used function and didn't really use my main, therefore I left it out and apparently you can't do that. This time i have no idea what it is. Below is my code... if you can help me figure it out that would be much appreciated. I am just not getting the hang of this coding/programming thing at all.


#include <iostream>
#include<stdlib.h>

#define Max_Array_Size 10 //defines the maximum size of the array

//Pre-defined functions needed for this program

void PrintArry(int arryData[]);//this will print the array data when asked
void Mix_It_Up(int arryData[]);//you need this to mix up the values to make data unsorted

void SelectionSort(int arryData[]);//the is the function that will perform the selection sort on the array
void BubbleSort(int arryData[]);//this is the function that will perform the bubble sort on the array
void InsertionSort(int arryData[]);//this is the function that will perform the insertion sort on the array


//before every sort function we use the mix it up function to mix the data within the array, otherwise sorting would be pointless
int main()
{
int arryData[Max_Array_Size]; //this is our array

Mix_It_Up(arryData); //this will fill the array with random data
std::cout << "Data Before Sorting...." ;
PrintArry(arryData);

//scans array and on each pass, pulls the next value in line.
SelectionSort(arryData);
std::cout << "Data before Selection Sort....";
PrintArry(arryData);

Mix_It_Up(arryData); //this will fill the array with random data
std::cout << "Data Before Sorting...." ;
PrintArry(arryData);

//bubble sorts compare adjacent cells and swaps them if they are in the wrong order
BubbleSort(arryData);
std::cout << "Data before Bubble Sort....";
PrintArry(arryData);

Mix_It_Up(arryData); //this will fill the array with random data
std::cout << "Data Before Sorting...." ;
PrintArry(arryData);

//sorts one element at a time
InsertionSort(arryData);
std::cout << "Data before Insertion Sort....";
PrintArry(arryData);

return 0;
}

void Mix_It_Up(int arryData[])
{
for(int i = 0; i<Max_Array_Size; i++) //use for loop to walk the array
{
arryData[i] = rand() % 20+1; //this is the data we will use in our array
}//end for loop
}//end of function

void PrintData(int arryData[])
{
for(int i =0; i < Max_Array_Size; i++)
std::cout<< arryData[i]<< " " ; //this will print out the contents of the array
}//end of function

void SelectionSort(int arryData[])
{
//present_cell is the current cell within the array
//smallest is the smallest number within the array
//holdData is a temporary storage
//walker is the thing we use to walk the array
int Present_Cell, smallest, holdData, walker;

for(Present_Cell = 0; Present_Cell < Max_Array_Size; Present_Cell++) //we set the current cell to array 0
{
smallest = Present_Cell; //we make smallest = to the current cell so we may compare it to the next
for(walker = Present_Cell +1; walker <= Max_Array_Size; walker ++) //for loop is used to check smallest against other cells
{
if(arryData[walker] < arryData[smallest]) //if the walker is less than smallest
smallest = walker; //then we swap them, so now walker>smallest
holdData = arryData[Present_Cell]; //we use the holdData to hold the data within the current cell
arryData[Present_Cell] = arryData[smallest]; //then we set current to smallest so we may again check against other cells
arryData[smallest] = holdData; //then make smallest equal to the holdData, so now smallest is again the smallest
}//end second for loop
}//end first for loop
}//end function

void BubbleSort(int arryData[])
{
//Present_Cell is the current cell within the array, walker is what we use to walk the array, temp is a temporary holder.
int walker, Present_Cell, temp;
bool sorted = false; //use boolean because the list is either sorted or not, true or false

for(Present_Cell = 0, sorted = false; Present_Cell <= Max_Array_Size && !sorted; Present_Cell++)//when you are at array 0 the list is not sorted
if(arryData[walker] < arryData[walker-1])//if array @ walker is < walker-1
{
sorted = false; //then array is not sorted
temp = arryData[walker]; //we use temp to store the walker
arryData[walker]= arryData[walker-1];//now walker is equal to walker-1
arryData[walker-1] = temp; //walker-1 is now equal to temp
}//end if statement
}//end function

void InsertionSort(int arryData[])
{
//Present_Cell is the current cell in array, holdData is used to temp hold data, walker is used to walk array
int Present_Cell, holdData, walker;

for(Present_Cell = 1; Present_Cell <= Max_Array_Size; Present_Cell++)//start at 1 not 0
{
holdData = arryData[Present_Cell]; //make holdData hold the current cell
for(walker = Present_Cell - 1; walker >= 0 && holdData < arryData[walker]; walker--)
arryData[walker+1] = arryData[walker]; //walker+1 = walker
arryData[walker+1] = holdData;//walker+1 now = hold slot
}//end for loop
}//end function
http://www.cplusplus.com/forum/beginner/1/

When You Ask
Use meaningful, specific subject headers

The subject header is your golden opportunity to attract qualified experts' attention. Don't waste it on babble like 'Please help me' Don't try to impress us with the depth of your anguish; use the space for a super-concise problem description instead.

More generally, imagine looking at the index of an archive of questions, with just the subject lines showing. Make your subject line reflect your question well enough that the next guy searching the archive with a question similar to yours will be able to follow the thread to an answer rather than posting the question again.


If you're having trouble interpreting your compiler/linker's error messages, supply the messsages in question.

Use code tags to surround your code. (The <> button to the right when you're editing.)

You declare a function void PrintArry(int arryData[]);. You try to call it in main, but you never define it. That is the source of your problem.

Topic archived. No new replies allowed.