Im really new (48 hrs) and slowy grasping this stuff.
I think I have the majority of errors taken care of but Im still getting one that says
"[Linker error] undefined reference to 'number_sort(int *, int)'
If anyone feels like helping, I would really appreciate it. Feel free to tear it apart but please try to go slow as I still dont understand much.
Code:
#include <iostream>
using std::cout;
using std::cin;
void number_sort(int array[], int maxnum);
int main(void)
{
// DECLARE VARIABLES
int maxnum; // This is how many numbers we will be using
int ToBeSorted; // Values which will eventually be in ascending order
int Array[100]; // Declare Array with no more than 100 elements
int Copied; // If value is < than ToBeSorted Value then copy value to Storage
int Storage; // This holds values temp until copy is complete
cout << "How many numbers do you want to sort? ";
cin >> maxnum;
cout << "\nPlease begin entering " << maxnum << " numbers.\n";
ToBeSorted = 1;
// GATHER DATA
for(ToBeSorted = 1; ToBeSorted < maxnum + 1; ToBeSorted++){
/*
Use ToBeSorted as the array subscript and loop until we have all numbers needed (maxnum).
"ToBeSorted" is set to 1 for the first number entered and since we increased ToBeSorted by
one, the same must be done to "maxnum"
*/
cout << "\nEnter number " << ToBeSorted << "\n";
cin >> Array[ToBeSorted]; // Initialize array with values
cout << "\n";
}
// SORTING
number_sort(Array, ToBeSorted);
// DISPLAY
for(ToBeSorted = 1; ToBeSorted < maxnum + 1; ToBeSorted++){
cout << Array[ToBeSorted] << "\n";
}
}
void nubmer_sort(int array[], int maxnum)
{
int ToBeSorted; // Values which will eventually be in ascending order
int Array[100]; // Declare Array with no more than 100 elements
int Copied; // If value is < than ToBeSorted Value then copy value to Storage
int Storage; // This holds values temp until copy is complete
for(ToBeSorted = 1; ToBeSorted < maxnum + 1; ToBeSorted++){ // Loop until we reach final value
for(Copied = ToBeSorted+1; Copied < maxnum + 1; Copied++){ // Loop again and move values if needed
if(Array[ToBeSorted] > Array[Copied]){ // if ToBeSorted(1) is greater than Copied(2) then do next 3 lines
Storage = Array[ToBeSorted]; // Move ToBeSorted into temp Storage
Array[ToBeSorted] = Array[Copied]; // Move the smaller number from Copied to the ToBeSorted array
Array[Copied] = Storage; // Now copy the original value we got from ToBeStored (now in Storage) to the Copied array
}
}
}
}