I write most of my programs using only void function. They end up long and bloated because I often write the same code over and over again in each void function. I'm even confused by void functions though. The book says void functions don't return data but I make them do it. I'm using a void function to send data to a file and the screen. I use a void function to create the random number array. Then the other void functions use the random array, like sort it low to high. So I know they return data. In this program I created a 10 x 10 display twice and wrote to sceen and file twice. If I'm doing the same thing twice I know you can send the data i.e. print to file twice ,once sorted, once unsorted. Whenever I try and do function calls I end up a huge amount of errors. Also I'm creating the 10 x 10 display twice. Can't I somehow send the unsorted and sorted data to the same fuction to be formated and that be returned for display. Below are the functions without the statements. In main I have commented on what each function call does.
No one in my class asks any questions, but when I ask them whats going on they say they can't explain it only do it! They just keep compiling it and correcting the errors until it works, crazy!
Code:
//Function Prototypes
void randNum(int[]);
void bubbleSort(int[]);
void show(int []);
void tenByTen(int []);
//Called Functions
void randFunc(int firstArray[])
{
Statement
}
void bubbleSort(int firstArray[])
{
Statement
}
void tenByTen(int firstArray[])
{
Statement
}
int main()
{
srand((unsigned)time(0));//Seed random number generator
int firstArray[100];//initialize array
randFunc(firstArray);//call random number genertor function, fill array, print unsorted data to screen and file in 10 x 10 format
bubbleSort(firstArray);//Bubble sort array, lowest to highest
tenByTen (firstArray);// Format sorted numbers in 10 x 10 display, print to screen and append to same file
cout << endl;
return 0;
}
Comment