So I've been told to do a program in c++ where the user inputs a word and I have to instert it into an array, but the problem is when I have to invert the word:
#include <iostream>
using namespace std;
const int EOS = '.';
const int MAX = 30;
typedef char VectorC[MAX];
void showInversion (char word[MAX],int n)
{
for (int i = n; i <= n-1 ; i--){
cout << word[i];
}
}
int main()
{
VectorC word;
char c = 'a';
int i = 0, n = 0;
cout << "ENTER SEQUENCE:" << endl;
while (c!=EOS){
word[i] = c = cin.get();
i++;
n++; //length of the word
}
cout << "THE RESULT IS: " << showInversion(word,n);
return 0;
}
Output example:
ENTER A SEQUENCE:
COMPUTER.
THE RESULT IS: RETUPMOC