I am having some trouble with this program ..
if input is abaabcdbab output should read abcd.... program is supposed to delete the repeated characters and output only one of each character but it is not working .... and ideas would be welcome
//Reads the letters in an array and deletes all repeated letters.
//Requires a function called deleteRepeats, also a partially filled
//array that requires two arguments. The function will have two formal parameters:
//an array parameter and a formal parameter of type int that gives the number of array positions.
#include <iostream>
using namespace std;
const int DECLARED_SIZE = 10;
void fillArray(char a[], int size, int& numberUsed);
void sort(char a[], int numberUsed);
void deleteRepeat(char a[], int& n);
int indexOfFirst(const char a[], int startIndex, int numberUsed);
int main()
{
cout << "This program sorts characters and deletes any repeated characters.\n";
int size = 4, numberUsed;
char a[10];
fillArray(a, 10, numberUsed);
sort(a, numberUsed);
deleteRepeat(a, size);
cout << "In sorted order the letters are:\n";
for (int index = 0; index < numberUsed; index++)
cout << a[index] << " ";
cout << endl;
return 0;
}
void fillArray(char a[], int size, int& numberUsed)
{
cout << "Enter up to " << size << " letters or characters.\n"
<< "Mark the end of the list with a negative number.\n";
int next, index = 0;
cin >> next;
while ((next >= 0) && (index < size))
{
a[index] = next;
index++;
cin >> next;
}
numberUsed = index;
}
void sort(char a[], int numberUsed)
{
int indexOfNext;
for (int index = 0; index < numberUsed - 1; index++)
{
indexOfNext = indexOfFirst(a, index, numberUsed);
}
}
void deleteRepeat(char a[], int& n)
{
int i,j,k;
for(i=0; i<n-1; i++)
for(j=i+1; j<n; j++)
if(a[i]==a[j])
{
for(k=j; k<n; k++)
{
a[k]=a[k+1];
n--;
j--;
}
}
}
int indexOfFirst(const char a[], int startIndex, int numberUsed)
{
int min = a[startIndex],
indexOfMin = startIndex;
for (int index = startIndex + 1; index < numberUsed; index++)
if (a[index] < min)
{
min = a[index];
indexOfMin = index;
}
return indexOfMin;
}