Problem making a sum of digits calculator
Page 1 of 110 Replies  3218 Views  Last Post: 08 December 2012  12:10 PM
#1
Problem making a sum of digits calculator
Posted 06 December 2012  04:50 PM
Any help will be greatly appreciated
Replies To: Problem making a sum of digits calculator
#2
Re: Problem making a sum of digits calculator
Posted 06 December 2012  05:47 PM
As you separate each digit, you can add it to a variable.
Once you've done all digits, you can display the result.
I recommend that you place, above your Class statement, Option Strict On. This will help you get the data types right.
Please feel free to come back with questions if you have any problems.
#3
Re: Problem making a sum of digits calculator
Posted 07 December 2012  03:01 AM
Here's the pseudocode:
NUMBER = "1235" 'This should be integer to prevent decimal place SUM = 0 WHILE (NUMBER>0) SUM = SUM + (NUMBER/10) NUMBER = NUMBER/10 END WHILE
#4
Re: Problem making a sum of digits calculator
Posted 07 December 2012  03:03 AM
Here's the pseudocode:
NUMBER = "1235" 'This should be integer to prevent decimal place SUM = 0 WHILE (NUMBER>0) SUM = SUM + (NUMBER/10) NUMBER = NUMBER/10 END WHILE
#5
Re: Problem making a sum of digits calculator
Posted 07 December 2012  04:37 AM
#6
Re: Problem making a sum of digits calculator
Posted 07 December 2012  09:48 AM
November06, on 07 December 2012  04:03 AM, said:
Here's the pseudocode:
NUMBER = "1235" 'This should be integer to prevent decimal place SUM = 0 WHILE (NUMBER>0) SUM = SUM + (NUMBER/10) NUMBER = NUMBER/10 END WHILE
While it is certainly possible (and perhaps even preferable) to use Mod, your pseudocode does not use it, and will not return the result intended.
1235 should return 11 as the sum of its digits, but your method will result in 137. Plug it in, give it a try.
#7
Re: Problem making a sum of digits calculator
Posted 07 December 2012  10:28 AM
#8
Re: Problem making a sum of digits calculator
Posted 08 December 2012  05:16 AM
lar3ry, on 07 December 2012  09:48 AM, said:
November06, on 07 December 2012  04:03 AM, said:
Here's the pseudocode:
NUMBER = "1235" 'This should be integer to prevent decimal place SUM = 0 WHILE (NUMBER>0) SUM = SUM + (NUMBER/10) NUMBER = NUMBER/10 END WHILE
While it is certainly possible (and perhaps even preferable) to use Mod, your pseudocode does not use it, and will not return the result intended.
1235 should return 11 as the sum of its digits, but your method will result in 137. Plug it in, give it a try.
Sorry, It should have been
SUM = SUM + (NUMBER MOD 10)
instead of
SUM = SUM + (NUMBER/10)
#9
Re: Problem making a sum of digits calculator
Posted 08 December 2012  08:45 AM
#10
Re: Problem making a sum of digits calculator
Posted 08 December 2012  08:58 AM
