12345678910111213141516171819202122232425262728293031323334
#include<iostream> #include<string.h> using namespace std; string inputString, outputString, again; int main(){ cout << "Enter a phrase you want reversed: "; cin >> inputString; cout << endl; int nLength = inputString.length(); nLength--; while (1){ for(int nIndex = nLength; nIndex >= 0; nIndex--); { outputString+=inputString[nIndex]; } cout << "The reversed phrase is: " << outputString << endl; cout << "Again? (y/n)"; cin >> again; if(again == "y" ){ cout << "Enter a phrase you want reversed: "; cin >> inputString; } if (again !="y"){ cout << "Please close the window." << endl; break; } } return 0; }
1234
if(again == "y" ){ memset(outputString, 0, nIndex) cout << "Enter a phrase you want reversed: "; cin >> inputString;}
12345
if(again == "y" ){ outputString.clear(); cout << "Enter a phrase you want reversed: "; cin >> inputString; }
for(int nIndex = nLength; nIndex >= 0; nIndex--); // this one.