944,047 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 6011
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Jul 7th, 2007
0

Word Descrambler....

Expand Post »
I am a beginner at C++, (thought not really to programming in general)...........................

and decided to challenge myself to write something: A descrambler...........

I know what I need to do.
I need to:

C++ Syntax (Toggle Plain Text)
  1. (any code is pseudocode)
  2. open scrambled words file
  3. open the wordlist
  4.  
  5. :loop
  6. get scrambled words
  7. get wordlist
  8. compare length of a scrambled word to all of the wordlist words
  9. if(length of two words is the same) compare amount of each letter;<-----compare how many a's, b's, c's, etc.
  10. if(amount of each letter is the same) print unscrambled word from wordlist to a file
  11. goto loop(when whitespace detected)
  12.  
  13. The unscrambled wordlist is in a file, and every word is on a new line.
  14. could i somehow detect the whitespace, and it switch down and restart the loop?
  15.  


i know how to open the files, and get their contents...

what i don't know is how to find how many certain letters are in a word, and how to find the length of the word(actually, I have some idea,...just using a loop)





thanks,
Kodiak( A n00by C++ programmer)
Reputation Points: 15
Solved Threads: 0
Light Poster
kodiak is offline Offline
38 posts
since Jul 2007
Jul 7th, 2007
0

Re: Word Descrambler....

FIXED!

C++ Syntax (Toggle Plain Text)
  1.  
  2. //get the length of a string using the sexually transmitted library
  3. #include <iostream>
  4. #include <cstdlib>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. string foo = "mystring";
  10. cout << foo.length();
  11. }

EDIT: because i only have so long to edit i may have to double post to get some more info in thurr.
Last edited by Killer_Typo; Jul 7th, 2007 at 11:03 pm.
Reputation Points: 152
Solved Threads: 39
Master Poster
Killer_Typo is offline Offline
778 posts
since Apr 2004
Jul 7th, 2007
0

Re: Word Descrambler....

thanks alot!!! now i just need a way to compare letters...!! thanks!!!!!!!!!!!!
Reputation Points: 15
Solved Threads: 0
Light Poster
kodiak is offline Offline
38 posts
since Jul 2007
Jul 7th, 2007
0

Re: Word Descrambler....

Click to Expand / Collapse  Quote originally posted by kodiak ...
thanks alot!!! now i just need a way to compare letters...!! thanks!!!!!!!!!!!!
counting letters is quite easy, you can easily take a string of foo length and run a foreach on it

C++ Syntax (Toggle Plain Text)
  1. string foo = "some string of some length";
  2.  
  3. for each ( char letter in foo )
  4. {
  5. cout << letter << endl;
  6. }

i have the logic already written up for counting letters but you should play around with it some more before i hand the code over :-D
Reputation Points: 152
Solved Threads: 39
Master Poster
Killer_Typo is offline Offline
778 posts
since Apr 2004
Jul 8th, 2007
0

Re: Word Descrambler....

thanks, but that code didn't work.... maybe explain to me how to use it??
Reputation Points: 15
Solved Threads: 0
Light Poster
kodiak is offline Offline
38 posts
since Jul 2007
Jul 8th, 2007
0

Re: Word Descrambler....

Click to Expand / Collapse  Quote originally posted by kodiak ...
thanks, but that code didn't work.... maybe explain to me how to use it??
didnt work how so?

didnt work as in it wouldnt compile?

or didnt work as in it wouldnt count the letters?

make sure you are including the right files to use strings from the standard type libraries

C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. string mystring = "hello world";
  8. for each (char letter in mystring)
  9. {
  10. cout << letter << endl;
  11. }
  12. }
will output
C++ Syntax (Toggle Plain Text)
  1. h
  2. e
  3. l
  4. l
  5. o
  6.  
  7. w
  8. o
  9. r
  10. l
  11. d
Reputation Points: 152
Solved Threads: 39
Master Poster
Killer_Typo is offline Offline
778 posts
since Apr 2004
Jul 8th, 2007
0

Re: Word Descrambler....

AFAIK, thats not standard C++. There is no 'for...each' construct in C++. Its C++/CLI.
Super Moderator
Featured Poster
Reputation Points: 3241
Solved Threads: 720
Failure as a human
~s.o.s~ is offline Offline
8,873 posts
since Jun 2006
Jul 8th, 2007
0

Re: Word Descrambler....

Click to Expand / Collapse  Quote originally posted by ~s.o.s~ ...
AFAIK, thats not standard C++. There is no 'for...each' construct in C++. Its C++/CLI.
well damn my compiler for giving me access to for each.

let's write a while statement then!

C++ Syntax (Toggle Plain Text)
  1. string foo = "super duper long string of wooorrrdddsss";
  2. int c = 0;
  3. while ( c < foo.length() )
  4. {
  5. cout << foo[c];
  6. c++;
  7. }
Last edited by Killer_Typo; Jul 8th, 2007 at 2:53 am.
Reputation Points: 152
Solved Threads: 39
Master Poster
Killer_Typo is offline Offline
778 posts
since Apr 2004
Jul 8th, 2007
1

Re: Word Descrambler....

Sorry I wasn't more specific...

I use dev C++(which I love) , and it wasn't compiling.

I then tried to compile it in visual c++ and it worked fine, but I dont think you understand exactly what I need, it's my fault, I explained my problem badly.

I need some thing that will read the word "kodiak"
and spit out:

6 characters long.
uses "k" 2 times.
uses "o" 1 time.
uses "d" 1 time.
uses "i" 1 time.
uses "a" 1 time.
...........................................If the code you posted does do this, then I'm sorry....

I don't need you to write all of my code for me, i can get the file to go to an array, and compare them, and finally write the answers to a file, etc.
I just need code that will tell me what i have posted above.

I am very grateful for you helping me become a better C++ programmer,

Kodiak
Reputation Points: 15
Solved Threads: 0
Light Poster
kodiak is offline Offline
38 posts
since Jul 2007
Jul 8th, 2007
0

Re: Word Descrambler....

Click to Expand / Collapse  Quote originally posted by kodiak ...
Sorry I wasn't more specific...

I use dev C++(which I love) , and it wasn't compiling.

I then tried to compile it in visual c++ and it worked fine, but I dont think you understand exactly what I need, it's my fault, I explained my problem badly.

I need some thing that will read the word "kodiak"
and spit out:

6 characters long.
uses "k" 2 times.
uses "o" 1 time.
uses "d" 1 time.
uses "i" 1 time.
uses "a" 1 time.
...........................................If the code you posted does do this, then I'm sorry....

I don't need you to write all of my code for me, i can get the file to go to an array, and compare them, and finally write the answers to a file, etc.
I just need code that will tell me what i have posted above.

I am very grateful for you helping me become a better C++ programmer,

Kodiak
awesome you are on the right track

so if we have a statement to itterate through all of the letters in the word it is now about counting each of the letters as they appear

case/switch will work for this

psuedo code:

while counting through each letter in the word

check to see what letter you are

check to see if you are a letter (not a space or symbol)

if you are a letter determin which letter you are

once i have determined the letter add you to my letter counter

etc...do this for each letter in the word
Reputation Points: 152
Solved Threads: 39
Master Poster
Killer_Typo is offline Offline
778 posts
since Apr 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Help Please - with String Manipulation
Next Thread in C++ Forum Timeline: using forks





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC