Word Descrambler....

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2007
Posts: 36
Reputation: kodiak is an unknown quantity at this point 
Solved Threads: 0
kodiak's Avatar
kodiak kodiak is offline Offline
Light Poster

Word Descrambler....

 
0
  #1
Jul 7th, 2007
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:

  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)
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 759
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Solved Threads: 35
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

Re: Word Descrambler....

 
0
  #2
Jul 7th, 2007
FIXED!

  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.
Dont forget to spread the reputation to those that deserve!
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 36
Reputation: kodiak is an unknown quantity at this point 
Solved Threads: 0
kodiak's Avatar
kodiak kodiak is offline Offline
Light Poster

Re: Word Descrambler....

 
0
  #3
Jul 7th, 2007
thanks alot!!! now i just need a way to compare letters...!! thanks!!!!!!!!!!!!
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 759
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Solved Threads: 35
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

Re: Word Descrambler....

 
0
  #4
Jul 7th, 2007
Originally Posted by kodiak View Post
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

  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
Dont forget to spread the reputation to those that deserve!
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 36
Reputation: kodiak is an unknown quantity at this point 
Solved Threads: 0
kodiak's Avatar
kodiak kodiak is offline Offline
Light Poster

Re: Word Descrambler....

 
0
  #5
Jul 8th, 2007
thanks, but that code didn't work.... maybe explain to me how to use it??
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 759
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Solved Threads: 35
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

Re: Word Descrambler....

 
0
  #6
Jul 8th, 2007
Originally Posted by kodiak View Post
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

  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
  1. h
  2. e
  3. l
  4. l
  5. o
  6.  
  7. w
  8. o
  9. r
  10. l
  11. d
Dont forget to spread the reputation to those that deserve!
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,648
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 473
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Word Descrambler....

 
0
  #7
Jul 8th, 2007
AFAIK, thats not standard C++. There is no 'for...each' construct in C++. Its C++/CLI.
I don't accept change; I don't deserve to live.

Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 759
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Solved Threads: 35
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

Re: Word Descrambler....

 
0
  #8
Jul 8th, 2007
Originally Posted by ~s.o.s~ View Post
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!

  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.
Dont forget to spread the reputation to those that deserve!
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 36
Reputation: kodiak is an unknown quantity at this point 
Solved Threads: 0
kodiak's Avatar
kodiak kodiak is offline Offline
Light Poster

Re: Word Descrambler....

 
1
  #9
Jul 8th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 759
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Solved Threads: 35
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

Re: Word Descrambler....

 
0
  #10
Jul 8th, 2007
Originally Posted by kodiak View Post
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
Dont forget to spread the reputation to those that deserve!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC