Albatross and firedraco,
Thank you both very much for your replies--it's always those simple details that slide past tired eyes after hours at the screen. I am now stuck on some logic issues. It appears my searchArray function is not outputting a false value and so d_array is being populated even if the new value test_num is a duplicate. I'm also unsure as to whether I understand the logic of the user input properly to begin with: I am trying to get it to where each entry followed by a hit of the return key will be passed to function searchArray and only upon getting a true bool value of not_dup will d_array get populated and given the subscript of whatever number (dist_num) the program has progressed through. Thanks again everyone, it really helps to get those little pointers that give the aha moment! Also, I made some changes to the previous code:
int main ()
{
const int AR_LEN = 10;
int d_array[AR_LEN], count, dist_num = 0, test_num;
bool not_dup;
cout << "Please enter ten integers, hitting return after each one: \n";
for (count = 0; count < AR_LEN; count++)
{
cin >> test_num;
not_dup = searchArray(d_array, dist_num, test_num);
if (not_dup)
{
d_array[dist_num] = test_num;
dist_num += 1;
}
}
cout << "You entered " << dist_num << " distinct numbers: ";
for (count = 0; count < dist_num; count++)
cout << d_array[count] << " ";
cout << endl;
return 0;
}
//****************************************************************
//Definition of function searchArray. *
//This function examines the stored values in d_array for *
//duplicates and returns the bool variable not_dup accordingly.
*
//****************************************************************
bool searchArray(int d_array[], int dist_num, int test_num)
{
int index = 0;
bool not_dup = true;
while (index < (dist_num + 1) && !not_dup)
{
if (d_array[index] == test_num)
{
not_dup = false;
}
index++;
}
return not_dup;
}