_Treant
Newbie level 1
I got this code to find the nth character of a string:
#include <iostream>
#include <string>
using namespace std;
int main ()
{
char ans;
repeat:
string str;
char c;
int n;
cout<<"input: & number";
getline(cin,str);
cin>>n;
c = str.at(n-1);
cout<<"char = "<<c;
n=n <= 0 && n < str.length();
{
cout << "Do you want to try again(y/n)? ";
cin>>ans;
if (ans == 'y')
goto repeat;
else if (ans == 'n')
exit(1);
else
cout<<"INVALID CHOICE"<<endl;
}
return 0;
}
The program's working fine on the first try but when you enter y to try again, input the string, it shows the "Abnormal Program Termination" error. Please help...
#include <iostream>
#include <string>
using namespace std;
int main ()
{
char ans;
repeat:
string str;
char c;
int n;
cout<<"input: & number";
getline(cin,str);
cin>>n;
c = str.at(n-1);
cout<<"char = "<<c;
n=n <= 0 && n < str.length();
{
cout << "Do you want to try again(y/n)? ";
cin>>ans;
if (ans == 'y')
goto repeat;
else if (ans == 'n')
exit(1);
else
cout<<"INVALID CHOICE"<<endl;
}
return 0;
}
The program's working fine on the first try but when you enter y to try again, input the string, it shows the "Abnormal Program Termination" error. Please help...