Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Coding Academy - WordScramble Homework Help

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming
View previous topic :: View next topic  
Author Message
rikoshay2020



Joined: Sun Jan 24, 2010 6:17 pm
Posts: 6

PostPosted: Fri Feb 05, 2010 3:59 pm    Post subject: Coding Academy - WordScramble Homework Help Reply with quote

Hi,

I've got all of the homework for WordScramble done apart from part 4 which is driving me somewhat nuts! Mostly because I thought it should be really easy and whatever I try just seems to end up compiling fine but then not functioning quite as I want it.

I've tried several different approaches and the one I think was in the right direction was adding an extra bit to the WordIsPossible method whereby if the int value of letters = 0 (i.e. all letters have been used) it returns false and the word is not possible. I realise that this would not exclude anagrams. This felt right as I wasn't simply comparing input against PromptLetters (which I tried and still couldn't get to work).

Any pointers greatly appreciated as I really want to try and get it sorted before moving on to Project 3.

Cheers.
Back to top
View user's profile Send private message
Hudzilla
Site admin


Joined: Mon Apr 04, 2005 12:52 pm
Posts: 265
Location: LXF Towers

PostPosted: Fri Feb 05, 2010 6:43 pm    Post subject: Reply with quote

Hey!

You're right to want to complete the homework before continuing - it sounds crazy, but banging your head against a wall before solving the problem will really help you in the long run Smile

I don't know why your code isn't compiling; you'd have to give me some source code and the error messages to help with that. The homework you're referring to asks you to stop the player from entering the same word used to generate their prompt letters. So, if the letters are "w o m b a t" don't let them enter the word "wombat".

The text tells you that the smart solution isn't to compare against the prompt letters. The reason for this is that the prompt letters have spaces between every letter, which is painful to compare against.

So, you have two options here:

1) Creating a new set of prompt letters involves pulling a word from our dictionary. How about adding that word straight to the Used List?

2) What about storing the chosen word in a new variable, then comparing the player's against that?


Paul
Back to top
View user's profile Send private message Visit poster's website
rikoshay2020



Joined: Sun Jan 24, 2010 6:17 pm
Posts: 6

PostPosted: Sat Feb 06, 2010 1:34 am    Post subject: Reply with quote

Thanks Paul. I sorted it with option 2 - creating a new variable. Copying word (not PromptLetters which was where I was going wrong) into it and adding a new else condition. On to project three! Thanks. Rik
Back to top
View user's profile Send private message
bargem



Joined: Sat Feb 06, 2010 6:42 pm
Posts: 1

PostPosted: Sat Feb 06, 2010 8:34 pm    Post subject: WordScramble Homework Part 4 Reply with quote

Hi there!

Thanks Rikoshay2020 for asking the question and to Paul for providing a couple of ways into the problem.

Like Rikoshay2020, I'd spent ages trying to figure out how to get this to work and didn't want to progress to Project Three until I'd cracked it.

First I tried to compare user input with PromptLetters (despite Paul's advice not to in the homework), but then realized PromptLetters had spaces between each letter. So I then tried to create a method to put spaces into the input word before comparing to PromptLetters - couldn't get that to work Sad . So then tried to create a method to remove the spaces from PromptLetters before checking against input - couldn't get that to work either Mad .

So have now also tried Paul's second option and created a new variable to hold the word taken from the wordlist file - which is set before the spaces are added to PromptLetters. This is then compared with the user's input in my new method. It works! Very Happy

Cheers! On to Project Three!!
Back to top
View user's profile Send private message
branmask



Joined: Thu Feb 18, 2010 1:19 am
Posts: 14

PostPosted: Thu Mar 04, 2010 7:45 am    Post subject: Reply with quote

Yes, thanks Paul for the suggestions. I figured out a very simple way to use your first suggestion. It has something to do with UsedList.Add and GetLetters. Amazing how something can seem so complicated, yet be so simple... Smile Thanks again.


Warning! spoiler ahead. code to follow. if you want to figure it out for yourself, don't read the rest of my comment...




GetLetters();
Console.WriteLine(PromptLetters);
UsedList.Add(PromptLetters);
Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast