Hello ladies and gents,
I had to do an exercise in wich I was required to compair two standaardtype strings opposits, meaning: name = "Johan", name2 = "nahoJ"
The idea was to return a bool value True or False. I did this with the following code I wrote:
#include <iostream>
#include <string>
using namespace std;
bool compair(const string &name, const string &name2)
{
int i, j;
if (name.length() != name2.length())return false;
for(i = name.length() - 1, j = 0;i >= 0 ;i--, j++)
{if (name[i] != 0 name[j]) return false;}
return true;
}
int main()
{
string name = "Johan", name2 = "nahoJ";
int c = compair(name, name2);
if(c == 1)
cout<<"True!"<<endl;
else
cout<<"False!"<<endl;
cout<<"Press any key to continue!\n";cin.get();
return 0;
}
Alltough I managed to get 'a' solution, I was wondering if any of you could tell me how I could improve/shorten or make the code more clearly to follow :?:
The idea is solely to try and code a program as best as possible.
Thanks for any assistance ;)