It seems like in order to solve this problem, I may have to use arrays or possibly assign individual chars based on the input number and etc....but we haven't been taught any of this yet so why would this task be relevant right now?? Very frustrating. Yes i could look at others examples and go off of that but that's walking backwards.
Presido
Level 4
Why does it seem like i am needing to use concepts here that we have yet to be taught?
Resolved
Comments (4)
- Popular
- New
- Old
You must be signed in to leave a comment
Michael Brimage
11 February 2020, 14:20solution
I will try to help based on my current understanding (level 4 and without the use of loops). I broke the three digit number into ones, tens and hundreds. Step 1: using mod 10 (number % 10) returned the ones digit == number1. Step 2: divide number by ten (number /10) will yield a double digit number, which you should return the remainder of ( number2 % two-digit number). This will provide the tens number (the "4"). Step 3, divide by 100 to get the final digit. Step 4, return the sum. I know this is verbose, but I hope it helps.
+2
Guadalupe Gagnon
22 January 2020, 15:28
Did you know that a very large chunk of work done by professional programmers is researching ways to solve a problem. In your comment you described 2 valid ideas (array or individual chars) to solve this problem, but then you give a reason not to do either. There are literally as many different ways to solve this task as there are people to solve it. I do like that you do not want to just look at other people's way to solve this, but you can still google ways to implement the ideas that you came up with.
Be prepared to fail..... a lot; but remember that doing so is the best way to learn programming. The best programmers have inquisitive minds and also enjoy solving problems.
A little tip: If you get stuck on a problem just skip it for a level or two. Codegym tasks get ahead of the lessons and you will find the ways to solve shortly thereafter. They do this on purpose as a way to teach you creative problem solving.
Also, if you want a book suggestion that every aspiring programmer should read, look into "Think Like a Programmer" by V. Anton Spraul.
+7
Guadalupe Gagnon
22 January 2020, 15:38solution
Using what you know already, simple math operations, here is a tip to solve this problem:
The task uses 546 as an input. To isolate the first digit of the number you can do this:
If you divide 546 by 10, the result would be 54 (because its an int there would be no decimal value), you then multiply that by 10 and you would have 540. If you take 546 and subtract 540, you are left with 6. This isolates the first digit for you. The code would look like this:
+7
Presido
26 January 2020, 03:23
Thank you very much for taking the time to share your input with me. You make very valid points, i appreciate that.
+1