|
-
Feb 8th, 2013, 01:09 PM
#1
Thread Starter
Addicted Member
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
dim jenn as geek = true
Learning ~ Visual Basic 2010 ~ in free time between college/work -
currently looking for a 'programming buddy' / 'coder friend' / and or 'mentor'. p.m. me if you
have ANY free time AT ALL I'm like 33% of a novice level ~ willing 2 listen/learn +
i am totally super motivated & promise to make an effffin amazing protege!!! #swag
| -_-_- -_-_- |
...W.T..F!?.....
||| Matter on the atomic/quantum level isn't solid or even matter at all. It can also exist in at least 2 places simultaneously (demonstrated in lab). It's position can only be established when it's actually observed. If we turn our back on it... it goes back to a wave form. History show's that every previous generation (since the beginning of time) got almost everything wrong. Then it might very well stand to reason that up is down & right can be wrong. Admit it.. our combined perception of reality is just that, we know absolutely nothing of actual reality & to think we do is simply subscribing to a "ignorance is bliss" mantra |||
-
Feb 8th, 2013, 01:17 PM
#2
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).
My usual boring signature: Nothing
 
-
Feb 12th, 2013, 12:14 AM
#3
Thread Starter
Addicted Member
Re: newb help: simple console addittion code, need help with variable addittion
 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
dim jenn as geek = true
Learning ~ Visual Basic 2010 ~ in free time between college/work -
currently looking for a 'programming buddy' / 'coder friend' / and or 'mentor'. p.m. me if you
have ANY free time AT ALL I'm like 33% of a novice level ~ willing 2 listen/learn +
i am totally super motivated & promise to make an effffin amazing protege!!! #swag
| -_-_- -_-_- |
...W.T..F!?.....
||| Matter on the atomic/quantum level isn't solid or even matter at all. It can also exist in at least 2 places simultaneously (demonstrated in lab). It's position can only be established when it's actually observed. If we turn our back on it... it goes back to a wave form. History show's that every previous generation (since the beginning of time) got almost everything wrong. Then it might very well stand to reason that up is down & right can be wrong. Admit it.. our combined perception of reality is just that, we know absolutely nothing of actual reality & to think we do is simply subscribing to a "ignorance is bliss" mantra |||
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|