Skip to content

Instantly share code, notes, and snippets.

@hr1383
Last active December 7, 2015 06:02
Show Gist options
  • Save hr1383/182c78fe963605778b19 to your computer and use it in GitHub Desktop.
Save hr1383/182c78fe963605778b19 to your computer and use it in GitHub Desktop.

Revisions

  1. hr1383 revised this gist Dec 7, 2015. 1 changed file with 19 additions and 15 deletions.
    34 changes: 19 additions & 15 deletions test.cpp
    Original file line number Diff line number Diff line change
    @@ -1,17 +1,21 @@
    void greaterThanYerAvg(int array[], int arraySize, double average, ofstream & newFile) {

    int num;
    int avgCount
    for (int count = 0; count < arraySize; count++) {
    if (array[count] > average) {
    num = array[count];
    newFile << num << "\t";
    avgCount++
    if ((avgCount + 1) % 5 == 0) {
    newFile << endl << endl;
    }
    change this
    for (count; count < arraySize-1; count++) {
    for (secondCounter = count + 1; secondCounter < arraySize; secondCounter++) {
    if (rec[count].salary > rec[secondCounter].salary) {
    temp = rec[count].salary;
    rec[count].salary = rec[secondCounter].salary;
    rec[secondCounter].salary = temp;
    }
    }

    //newFile << endl << endl;
    }
    }
    to
    // you need to swap the entire record
    for (count; count < arraySize-1; count++) {
    for (secondCounter = count + 1; secondCounter < arraySize; secondCounter++) {
    if (rec[count].salary > rec[secondCounter].salary) {
    temp = rec[count];
    rec[count] = rec[secondCounter];
    rec[secondCounter] = temp;
    }
    }
    }
  2. hr1383 created this gist Dec 6, 2015.
    17 changes: 17 additions & 0 deletions test.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    void greaterThanYerAvg(int array[], int arraySize, double average, ofstream & newFile) {

    int num;
    int avgCount
    for (int count = 0; count < arraySize; count++) {
    if (array[count] > average) {
    num = array[count];
    newFile << num << "\t";
    avgCount++
    if ((avgCount + 1) % 5 == 0) {
    newFile << endl << endl;
    }
    }

    //newFile << endl << endl;
    }
    }