|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi, I need help on coding for VB.net.
This kind of goes with the looping question I had before but I wasn't sure if I should post it there or not so I put it here. I have been working on this for a long time but something is wrong with it so it isn't working. But I have no clue as to what I did wrong so I was wondering if anyone could help me. The first loop is supposed to count the number of even positive integers that are <= N and the second loop is supposed to sum the first N odd integers. Thank you. Code:
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click Dim iPositiveIntegerN As Integer Dim iEven As Integer Dim iOdd As Integer Dim iKount As Integer iPositiveIntegerN = txtPositiveIntegerN.Text iKount = 0 Do Until iKount > 0 iEven = iPositiveIntegerN / 2 iKount = iKount + 1 Loop lblEven.Text = iEven iOdd = 3 iKount = 1 Do Until iKount > iPositiveIntegerN iOdd = iOdd + iKount iKount = iKount + 1 Loop lblOdd.Text = iOdd txtPositiveIntegerN.Focus() End Sub |
|
#2
|
|||
|
|||
|
I'm sorry if the title of the thread is confusing. I should have wrote "help" instead of "advice"
Sorry. |
|
#3
|
||||
|
||||
|
This code is in VB but u can convert into vb.net coz i dont know .net
N = Val(Text1.Text) ecount = 0 sumodd = 0 For i = 1 To N a = i Mod 2 If a = 0 Then ecount = ecount + 1 Else sumodd = sumodd + i End If Next MsgBox "Total even numbers : " & ecount MsgBox "Sum of Odd numbers : " & sumodd |
|
#4
|
|||
|
|||
|
Thank you very much everyone.
I finally figured out how to write it. I realized it was something really easy that I didn't notice, once again Thank you again. |
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > advice on coding |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|