Instantly share code, notes, and snippets.

# anonymous/P5P5 Created Oct 25, 2012

 { // Open scope block for part 6 cout << "\n\nStarting part 6 ...\n\n"; cout << "Input the minimum and maximum random int: "; int minRange, maxRange; cin >> minRange >> maxRange; cout << "Input the length of the vector: "; int vectorLength; cin >> vectorLength; vector hasRepeats(vectorLength); cout << " Vector beforehand: \t"; for (int i = 0; i < vectorLength; i = i + 1) { hasRepeats[i] = minRange + rand()%(maxRange - minRange + 1); cout << hasRepeats[i] << " "; } cout << "\n"; //////////////////////////////////////////// // Your code for part 6 gets patched in here // take out all multiples //check if v[i] is equal to previous ones //IF DUPLICATE, set to maxRange + 1 and then pop_back number of duplicates int counter = 0; for(int i = 0; i < vectorLength; i++) { for(int j = 0; j <= vectorLength ;j++) { if(hasRepeats[i] == hasRepeats[j]) { hasRepeats[i] = maxRange + 1; counter = counter + 1; } if(counter > 0) { for(int k = 0; k < counter; k++) { hasRepeats.pop_back(); } } } } //////////////////////////////////////////// cout << " Vector afterhand: \t"; for (int i = 0; i < hasRepeats.size(); i = i + 1) { cout << hasRepeats[i] << " "; } cout << "\n"; } // close the scope block for part 6 //////////////////////////////// End of Program ////////////////////////////////