Mail Archives: djgpp/2001/08/27/16:29:56
alright, this is as far as i can get it, i made some obvious fixes but the
same error is in.
//Exercise - Anagram Checker
#include <iostream>
#include <string>
using namespace std;
int main()
{
string input1;
string input2;
cout << "Enter a word: ";
cin >> input1;
cout << endl;
cout << "Enter another word: ";
cin >> input2;
cout << endl;
cout << "Let's see if your words are anagrams of each other. "
<< endl;
int length = 0;
if(input1.length() != input2.length())
{
cout << "\nYour words have different lengths, so they can't be anagrams!";
return 0;
}
else
length = input1.length();
int equal = 0;
int a = 0;
int b = 1;
int c = 0;
equal = input1.substr(a, b).compare(input2, c, b);
for( ; c < length ; )
{
for( ; a < length, equal == 0 ; a++)
{
input1.substr(a, b).compare(input2, c, b);
}
if(a >= length)
{
a = 0;
c++;
}
}
if(input1.substr(a, b).compare(input2, c, b) != 0)
{
cout << "The words are not anagrams.";
return 0;
}
else
{
cout << "The words are anagrams! What luck!";
return 0;
}
}
------------------------------------------------------------
Get your FREE web-based e-mail and newsgroup access at:
http://MailAndNews.com
Create a new mailbox, or access your existing IMAP4 or
POP3 mailbox from anywhere with just a web browser.
------------------------------------------------------------
- Raw text -