Page 1 of 3 123 LastLast
Results 1 to 10 of 22

Hybrid View

  1. #1
    Join Date
    Mar 2004
    Location
    near Orlando, Fl
    Posts
    5,302

    C# Homework 3 stuck

    I've been stuck for a pretty long time on this. Not sure what to do next or how to go about getting help since we're not really supposed to be posting code right?

    I've been banging my head on the desk for hours trying to figure out how to look at the randomNumber and the player's guess and break them down into their individual digits in order to see if the guess is close or not. I did get lists created for each category of guesses (hang in there, close, not close).

    I rewatched the class video and I didn't even see anything that showed how to do that, unless I completely missed it somehow.

    Anyone have any advice?
    The odds of hitting your target increase significantly when you aim at it.
    Check out my iOS games released in the App Store!
    Tricky Treasure Fall
    Tap 'n' Scrap
    UFO Escape From Earth

  2. #2
    Join Date
    May 2004
    Posts
    234
    I did my homework for week 3 in a weird way that still worked and then watching the open office they revealed an important piece that I just didn't know (or realise) and that allowed me to do the homework in a neater way.

    I can give you some hints, but tell me what hints you want to know about.

  3. #3
    Join Date
    Mar 2007
    Location
    Tawas, MI
    Posts
    19
    i looked at it this way i used strings.
    the player enters a string, and the random number is an int. so how can you take a int and make that into a string?
    okay now i have an string number and a string guess, so how do i compare them, strings are arrays of chars so how would you compare two arrays?

  4. #4
    Join Date
    Sep 2004
    Location
    USA
    Posts
    1,529
    Well DD there are two ways to go about getting the individual digits. If you have a list of ints, like I did, you can get the string number of your user's guessed number and brake that down into separate ints and put that into an int list. I don't recommend doing it that way, and in fact I wouldn't have done it that way, if Nelson and I hadn't had a misunderstanding that made me think that he wanted us to do it all with ints only, and not use strings.

    But to do it my way you would need to parse out the digits of a string and put them into an int. Remember int.parse. Also you can't use int.parse with chars, which is what a sting is, a list of chars, so you will have to use a .ToString on each char for that to work.

    Or you can forget about turning the chars into a list of ints and just keep it as a sting, which, again, is a list of chars. You can check between a string that holds a random number, in a string, and a string that holds the guessed number. Remember that string is a list. Think how you find a single index in a list. Hint []. Now all you have to do is loop through the index of both those numbers and do some logic tests.

    I hope this helps, and is not too little, or too much advice. Let us know how you are doing. I want you to get this.

  5. #5
    Join Date
    Apr 2010
    Location
    Alabama
    Posts
    100
    You can break integers down into individual digits mathematically as well. Just remember that ints are whole numbers with no decimal/fractional value.

    That is, if you don't want to cheat and do it the easy way =)
    Get your facts first, and then you can distort them as much as you please. - Mark Twain

  6. #6
    Join Date
    May 2004
    Posts
    234
    People are dropping small hints and Moosaroo mentioned what I called my weird way.
    My week 3 method was to keep all numbers integers and break it up mathematically eg. using loops you can find out if it is less than something, use that to reduce the number and so on, so 967, you would find out the 9, then minus to get 67, find out 6, then you are left with 7.

    Then the open office hours revealed to me that strings are like lists (should have realised this from the default console application main method). Because they are like lists, then you have the index at your disposal.

    I think with this, and all the hints above, you should manage now.

  7. #7
    Join Date
    Mar 2002
    Location
    Isle of Man, UK
    Posts
    918
    Heh, I noticed no-one posting anything after Gav closed down the other thread. Well done for speaking up DD.

    I think this homework just shows how varied the approaches to programming problems can be. The important part is that the program does what it's supposed to. So, whether that's a list of ints, a conversion to a string or a mathematical breakdown, if your guess is correctly handled, it doesn't matter how.

    I personally found ignoring the fact they were numbers was easier to get my head around, simply because manipulating strings is easier (and all the input is strings.) The only time I used int.parse was to check a number was actually entered...
    Mostly Human since '74

  8. #8
    Join Date
    Oct 2009
    Location
    The In Between. US
    Posts
    2,030
    I did it mathematically 1,10's, 100's. the string way was never something I thought of I don't think Nelson went over strings that way so it never occurred to me.
    elevating to new levels of knowledge (that's the plan at least )

  9. #9
    Join Date
    Mar 2004
    Location
    near Orlando, Fl
    Posts
    5,302
    I wish I couldve made it to the open office hours. I hope that not showing up doesn't appear to be an indication of not trying hard. I've got a full time job and so far office hours and classes except Thursday c# are when I'm at work.

    I'll watch that video tonight though.

    Thanks for all the ideas guys.
    The odds of hitting your target increase significantly when you aim at it.
    Check out my iOS games released in the App Store!
    Tricky Treasure Fall
    Tap 'n' Scrap
    UFO Escape From Earth

  10. #10
    Join Date
    Nov 2008
    Location
    41° 28′ 56″ N, 81° 40′ 11″ W
    Posts
    2,399
    Quote Originally Posted by DigitalDemigod View Post
    I wish I couldve made it to the open office hours. I hope that not showing up doesn't appear to be an indication of not trying hard. I've got a full time job and so far office hours and classes except Thursday c# are when I'm at work.

    I'll watch that video tonight though.

    Thanks for all the ideas guys.
    Now that I'm thinking about it, with my schedule, I could have definitely made those Monday afternoon classes without too much difficulty. Much better than Thursday nights, which would wind up taking up to the wee hours of the morning. Just didn't want to overwhelm myself between Blender and C#, even tho I would have loved both classes equally. Although Saturdays being how they are, I hardly ever really attend the Blender classes that much, either. The family always wants to go out for lunch on Saturdays, and some grocery shopping, and I'm always wanting to be here attending live classes with you guys. Tough to find that balance. Looks like I'll have to catch up with the C# 101 when I find more time to.
    Last edited by WedgeBob; 03-26-2012 at 06:28 PM.
    PC Specs: Antec 900 ATX Case, Gigabyte 790GX Mobo, AMD Phenom II x4 955, Corsair HX620W PSU, Corsair Vengeance 16GB (4x4GB) DDR3-1600, EVGA GTX 680 2GB GDDR5, 3D Vision Kit 2, LG 8x Blu-ray Burner, Intel X25-M SSD, 500GB+640GB WD Caviar Blacks, Win 7 Pro x64, DAS Pro K/B, MX518 Mouse, Logitech Z-2300 Speakers, Toshiba 32TL515U 32" 3DTV, Wacom Bamboo Fun Large Tablet.

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •