newb help: simple console addittion code, need help with variable addittion
Ok so i wrote this simple code for me to add several birth dates together, via console user input. You enter the first day digit, second day digit, first month digit, second month digit, & 1, 2, 3rd & 4th year digit. It adds them together. If it's equal to 11, 22, 33, or 44 it writes it out in this format * NUMBER *. Otherwise it just shows the total number on one line..i.e. 27
So what i need help doing is....adding the resulting 2 digits together (if they aren't already 11,22,33 or 44) & showing the result. I.E. if the result is 27, it would add 2 & 7...so it should write out 9 instead of 27. Or if it the result is 29...it should then write out * 11 * as per the IF..THEN.
So here is my current code. I'm using it to learn basic vb math/input operations. I'm starting all over from the beginning with vb & trying to learn the right way. So I would really appreciate someone simply re-writing my code, so i can see exactly how you do it via simple console. Thanks so much!
Code:
Sub Main()
Do
Console.WriteLine("First birth month number?")
Dim mm1 As Integer = Console.ReadLine()
Console.WriteLine("Second birth month number?")
Dim mm2 As Integer = Console.ReadLine
Console.WriteLine("First birth day number?")
Dim dd1 As Integer = Console.ReadLine
Console.WriteLine("Second birth day number?")
Dim dd2 As Integer = Console.ReadLine
Console.WriteLine("First birth year number?")
Dim yy1 As Integer = Console.ReadLine
Console.WriteLine("Second birth year number?")
Dim yy2 As Integer = Console.ReadLine
Console.WriteLine("Third birth year number?")
Dim yy3 As Integer = Console.ReadLine
Console.WriteLine("And the last birth year number is..")
Dim yy4 As Integer = Console.ReadLine
Dim Digitz As Integer
Digitz = mm1 + mm2 + dd1 + dd2 + yy1 + yy2 + yy3 + yy4
Console.WriteLine()
If Digitz = 11 Then
Console.WriteLine("* 11 *")
End If
If Digitz = 22 Then
Console.WriteLine("* 22 *")
End If
If Digitz = 33 Then
Console.WriteLine("* 33 *")
End If
If Digitz = 44 Then
Console.WriteLine("* 44 *")
End If
Console.WriteLine(Digitz)
Loop
End Sub
Re: newb help: simple console addittion code, need help with variable addittion
What's so bad about the way you are doing it?
To add the digits together, you have to get the digits.
To get the 1s digit:
onesDigit = variable Mod 10
To get the 10s digit:
tensDigit = variable \ 10 (note the direction of that slash, which is integer division rather than regular division).
Re: newb help: simple console addittion code, need help with variable addittion
Quote:
Originally Posted by
Shaggy Hiker
What's so bad about the way you are doing it?
To add the digits together, you have to get the digits.
To get the 1s digit:
onesDigit = variable Mod 10
To get the 10s digit:
tensDigit = variable \ 10 (note the direction of that slash, which is integer division rather than regular division).
ok sweet thanks! this is embarrisingly the very first code i wrote from scratch....ive done way more advanced stuff but after 'borrowing' others input/suggestions/work doh! lol
i will try this out asap