public
anonymous / P5P5
Created

  • Download Gist
P5P5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
{ // 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<int> 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 ////////////////////////////////

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.