0

can i anyone know how to solve a summation problem? in visual basic?
using do while? or do until?

here's my code

x = val(text1.text)
n = val(Text2.text)
c = text3.text

for example if the input of
x is 3 &
n is 2

therefor solving of that is like this

= 3^1 + 3^2
= 3 + 9
= 12

how can i came up this answer? and what if the value in text2.text or n is 3 so

= 3^1 + 3^2 + 3^3
= 3 + 9 27
= 39

and n shoulde be n>=1
and x>0

3
Contributors
15
Replies
16
Views
8 Years
Discussion Span
Last Post by aktharshaik
0

Hi,

You can write using any of the LOOP Structures,
You already know the Algorithm..
so what is the problem..?

Regards
Veena

0

Hi,

Try this :

Dim x As Integer
Dim n As Integer
Dim i As Integer
Dim Tot As Double
x = val(text1.text)
n = val(Text2.text)
If n <=0 Or x <1 Then
    MsgBox "Enter Proper Values"
    Exit Sub
End If
Tot = 0
For i = 1 To n
    Tot = Tot + (x ^ i)
Next
MsgBox Tot

Regards
Veena

0

thnx problem solve, last question how can i solve this?

N N+1
Xi - Xj
I = 1 j = I - 1

for example i input
in my text1.text value of 3
and text2.text value of 2

3 raised to 1 + 3 raised to 2 minu(-) 3 raised to zero + 3 raised to 1 + 3 raised to 2 + 3 raised to 3

the answer should -28

0

Hi,

Once you know the Logic, you can try playing around with the code.. But any way, here is the code:

Dim x As Integer
Dim n As Integer
Dim i As Integer
Dim Tot As Double
x = Val(text1.text)
n = Val(Text2.text)
If n <=0 Or x <1 Then
    MsgBox "Enter Proper Values"
    Exit Sub
End If
Tot = 0
For i = 1 To n
    Tot = Tot + (x ^ i)
Next
For i = 0 To (n +1)
    Tot = Tot - (x ^ i)
Next
MsgBox Tot

OR in One statement

Tot = - (x ^ (n+1)) + 1
MsgBox Tot

Regards
Veena

0

i have problem can you convert your code using do while or do until because our professor said we only use DO LOOP huhuhu please?

0

Hi,

Try it yourself....
Post the modified code, if there is problem with the code,
we will be glad to help you.

Regards
Veena

0

Dim x, n, i As Integer
Dim Tot As Double
x = Val(Text1.Text)
n = Val(Text2.Text)
If n <= 1 Or x < 0 Then
MsgBox "Enter Proper Values", vbCritical
Exit Sub
End If
Tot = 0
Do While i = 1 - n
Tot = Tot + (x ^ i)
Loop

Label1.Caption = Tot

the asnwer is 0 huhuhu

0
Dim x, n, i As Integer
    Dim Tot As Double

    x = Val(Text1.Text)
    n = Val(Text2.Text)
    If n <= 1 Or x <= 0 Then
        MsgBox "Enter Proper Values", vbCritical
        Exit Sub
    End If

    Tot = 0
    i = 1
    Do While i <=  n
        Tot = Tot + (x ^ i)
        i = i + 1
    Loop
0

wow great thank you so much sir! how about this sir i want to convert it into do while

Dim x As Integer
Dim n As Integer
Dim i As Integer
Dim Tot As Double
x = Val(text1.text)
n = Val(Text2.text)
If n <=0 Or x <1 Then
MsgBox "Enter Proper Values"
Exit Sub
End If
Tot = 0
For i = 1 To n
Tot = Tot + (x ^ i)
Next
For i = 0 To (n +1)
Tot = Tot - (x ^ i)
Next
MsgBox Tot

0
Dim x As Integer
    Dim n As Integer
    Dim i As Integer
    Dim Tot As Double

    x = Val(text1.text)
    n = Val(Text2.text)
    If n <=0 Or x <1 Then
        MsgBox "Enter Proper Values"
        Exit Sub
    End If

    Tot = 0
    i = 1
    Do While i <=  n
        Tot = Tot + (x ^ i)
        i = i + 1
    Loop
    i = 0
    Do While i <=  (n + 1)
        Tot = Tot - (x ^ i)
        i = i + 1
    Loop
    MsgBox Tot
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.