so basically I have to make a function that will swap a character with a character directly to its right.
1 2 3 4 5 6 7 8
void swap (char letters[11], int current)
{
//swap swaps the character at the index current with the
//character immediately to its right. If the current is
//at the end of the array, an error message is
//printed. Otherwise, a successful swap message is
//printed.
}
thats the function I have to use, im new with arrays and not exactly sure what to do, but I know it requires a for loop but I can't seem to get it.
help would be greatly appreciated, can someone point me in the right direction please!!! thanks.
void swap (char letters[11], int current)
{
int hold;
hold = letters[current];
letters[current] = letters[current + 1];
letters[current + 1] = hold;
if (current > current + 1)
{
cout << "Too close to the end of the array, cannot swap!" << endl;
}
else
{
cout << "Swap completed" << endl;
}
}