Here is my function to generate my numbers:
Expand|Select|Wrap|Line Numbers
- void randFunc() {
- int firstArray [100];//Declares an array of 100 items
- int min = -50;
- int max = 50;
- int randNum;
- for (randNum = 0; randNum < 100; randNum++) {
- firstArray[randNum] = rand()%(max - min + 1) + min;
- cout << setw (5) << firstArray[randNum] ;
- }//Close for
- }//close randfunc
My problems I'm sure are from a weak understanding of how to call functions and call arrays with functions. At this point I'm absoluting just guessing, with no rhyme or reason to changes in code. I'm simply throwing things against the wall to see if anything sticks.
Now here is my poor attempt at trying to sort it or at least the current version. My errors are down to three, that's better than the 17 I started with.
Expand|Select|Wrap|Line Numbers
- #include <iostream>
- #include <fstream>
- #include <cstdlib>
- #include <ctime>
- #include <iomanip>
- using namespace std;
- int randFunc();
- //int firstArray[100];
- int main () {
- //Generate random variable seed
- srand ((unsigned)time(0));//Seed random number generator
- // char yourFilename [80];//User supplied file name
- //Call random variable generator
- int randFunc();
- //Prompt user for name of file in which to store array
- cout << " Enter name the name of your file where you would like your array sorted array stored " << endl;
- // cin << yourFileName;
- return (0);
- }//close main
- int randFunc(int firstArray[100])
- {
- //int firstArray [100];
- //Declares an array of 100 items
- int min = -50;
- int max = 50;
- int randNum;
- for (randNum = 0; randNum < 100; randNum++)
- {
- firstArray[randNum] = rand()%(max - min + 1) + min;
- cout << setw (5) << firstArray[randNum] ;
- }//Close for
- return firstArray[100];
- }//close randfunc
- void bubbleSort (int firstArray [100])
- {
- int swap;
- for(int pass = 0; pass < 100; pass++)
- {
- for (int randNum = 0; randNum < 99 - pass; randNum++)
- {
- if (firstArray[randNum] > firstArray[randNum + 1])
- {
- swap = firstArray[randNum];
- firstArray [randNum] = firstArray [randNum + 1];
- firstArray[randNum + 1] = swap;
- cout << firstArray[randNum];
- cout << endl;
- }
- }
- }
- }
Yes this is homework, I'm not this sadistic normally!