There are several things wrong in your code.
You declared A
and B
as integer values. However then you (probably) try to read them as an char[]
(character array). Apart from the fact that this line cin >> char[] A
should give you a compiler error this doesn't even make sence. You can't store character values inside of an integer.
If you're trying to read a string or a character array then declare A
and B
as one.
Also the trailing if-statement at the end of your code will make your compiler complain. C++ is no scripting language. Statements won't be executed if they are not inside of a function.
The following program does what I think you try to approach:
#include <iostream>
#include <algorithm> // include algorithm to use std::reverse
using namespace std;
int main()
{
string A, B; // declare A and B to be a string, there is no need to declare them at global scope
cout << "word in A: ";
cin >> A;
cout << "word in B: ";
cin >> B;
reverse(A.begin(), A.end()); // reverses A
reverse(B.begin(), B.end()); // reverses B
cout << A << " " << B << endl; // prompt A and B
}
If you want to read integers and convert them to a string to reverse them, try the following:
#include <iostream>
#include <algorithm> // include algorithm to use std::reverse
using namespace std;
int main()
{
int A, B; // declare A and B to be a int
cout << "word in A: ";
cin >> A;
cout << "word in B: ";
cin >> B;
string strA(to_string(A)); // convert A into a string
string strB(to_string(B)); // convert B into a string
reverse(strA.begin(), strA.end()); // reverses string version of A
reverse(strB.begin(), strB.end()); // reverses string version of B
cout << strA << " " << strB << endl; // prompt strA and strB
}
Note: to use to_string()
you need to use the c++11 standard