The program runs fine however, when it's asked to input again, it's stuck.
#include <iostream>
#include <string>
using namespace std;
// Function of reverse
void reverse(string &Istr, int strlen)
{
int i;
char temp;
for (i=0; i < strlen /2; i++)
{
temp = Istr[i];
Istr[i] = Istr[strlen-i-1];
Istr[strlen-i-1] = temp;
}
}
int main()
{
start:
cout << "Enter string to reserve:" << endl; // input string
string str;
getline(cin, str);
int slength = str.length(); //length of the string
reverse(str, slength);
cout << "Reversed string: " << str << endl; // output the reversed string
again:
cout << "Do you want to insert another string (Y/N): "<< endl;
char ans;
cin >> ans;
if (ans == 'y')
{
str.clear();
goto start;
}
else if (ans != 'n')
goto again;
return 0;
}