Author Topic: Another programming question  (Read 3808 times)

Offline Spectre

  • VIP
  • Hero Member
  • **
  • Posts: 622
  • Rank: Unknown
  • Score: Unknown
  • Grossly incandescent
    • Team: No Terrorism
Another programming question
« on: January 21, 2017, 10:58:24 pm »
Hey guys, I had a test today in C programming (did well, 2 out of 3 tasks done xD), but I have had a problem with one of the tasks and I couldn't figure it out.

I had to write a code where user can input 2 double-digit numbers (the numbers would be loaded from an existing txt file) and the function should check if the sum of digits in first number matches the sum of digits in second number (for example, 23  and 41 checks out, so the output message should be "It's correct!"; otherwise, the message is "It's incorrect!"). Also, the program should stop if the numbers that user chose aren't double-digit.

I had no idea how to even make a condition for that function, even though I'm getting the feeling it's kinda easy xD So I'm interested to see how you guys would solve this, it'd be appreciated :)

Offline SoLoD

  • Hero Member
  • *****
  • Posts: 563
  • Rank: Unknown
  • Score: Unknown
    • Youtube stunting channel
Re: Another programming question
« Reply #1 on: January 21, 2017, 11:20:00 pm »
It is very easy.
Ur problem is to divide ur number to single digits and sum it.
You have number 23
divide it by 10, ur rest is 3. so, first digit is 3.
divide 2 by 10, ur rest is 2, second digit is 2.
3+2=5

How u do it in java (for deafault length of number)

By divide i mean finding remainder of the division, in java it is %.
« Last Edit: January 21, 2017, 11:25:15 pm by SoLoD »
You know the nice thing about the Bronx Zoo, Charlie? There's bars between you and the monkeys.

Offline Spectre

  • VIP
  • Hero Member
  • **
  • Posts: 622
  • Rank: Unknown
  • Score: Unknown
  • Grossly incandescent
    • Team: No Terrorism
Re: Another programming question
« Reply #2 on: January 22, 2017, 01:13:59 am »
Thanks for the reply, I'll try it out tomorrow and see if it works :)