- #1
- 12
- 0
Hello, the problem that I was asked to complete was ; Write a program that inputs a string and reverses it. After the string has been reversed you must convert it to an integer and then take the square root of the integer. (using atoi)
My code is as follows:
My problem is that my program isn't storing "new_string[L]" as anything so when I convert it to a integer nothing is there and the square root is zero. So my question to you all is how can i store "new_string[L]" so I can convert it to an integer using atoi?
Any advice would be delightful!
Thanks,
Z
My code is as follows:
Code:
int main ()
{
int i=0,L=50, S,x,;
double z;
char ori_string[50];
char new_string[50];
cout<<"Please enter a long string"<<endl;
cin.getline(ori_string,50);
for(i=0;i<L; i++)
{
new_string[i]=ori_string[L-1-i];
}
for(L=50-strlen(ori_string);L<50;L++)
{
cout<<new_string[L];
}
cout<<endl;
{
x=atoi(new_string);
z=sqrt(x);
cout<<"The square root of the reversed string is: "<<z<<endl;
}
system("pause");
return 0;
}
My problem is that my program isn't storing "new_string[L]" as anything so when I convert it to a integer nothing is there and the square root is zero. So my question to you all is how can i store "new_string[L]" so I can convert it to an integer using atoi?
Any advice would be delightful!
Thanks,
Z