Mail Archives: djgpp/2001/08/27/13:29:37
Sorry about that last message, i was insanely frustrated, next time ill be
more clear.
The good news is, now the program compiles fine, thanks to Hans' tip(surprised
i didnt catch that, its happened to me before).
However, upon compilation, the program does what it should up to the line that
says "Lets see if your strings are anagrams of each other."
Then it does an endl and shows a blinking cursor, and the program doesnt do
anything after that. I'm effectively stuck as to what to do, since there are
two for() loops and an if() statement after this which should be executed.
I'll repost the source, since ive made some changes, and besides, i dont
think anyone values my emails enough to store them :)
<-----------------------------------------------------------------------------
->
//Exercise - Anagram Checker
#include <iostream>
#include <string>
using namespace std;
int main()
{
string input1;
string input2;
cout << "Enter a line of text: ";
getline(cin, input1);
cout << endl;
cout << "Enter another line of text: ";
getline(cin, input2);
cout << endl;
cout << "Let's see if your strings are anagrams of each other. "
<< endl;
int greater = 0;
int lesser = 0;
if(input1.length() > input2.length())
{
greater = input1.length();
lesser = input2.length();
}
else
{
greater = input2.length();
lesser = 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 < lesser ; )
{
for( ; a < greater, equal == 0 ; a++)
{
input1.substr(a, b).compare(input2, c, b);
}
if(a >= greater)
{
a = 0;
c++;
}
}
if(input1.substr(a, b).compare(input2, c, b) != 0)
{
cout << "The strings are not anagrams.";
return 0;
}
else
{
cout << "The strings 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 -