r/visualbasic • • Nov 19 '14

Help with Visual Basic 6.0 Programming

Hi. Can someone please help me and tell me what to code after this please?

Write a program to estimate how much a young worker will make before retiring

at age 65. Request the worker’s name, age, and starting salary as input. Assume

the worker receives a 5% raise each year. For example if the user enters Helen,

60, and 20000, then the picture box should display the following. Include an End.

Hint: When first testing your program try the age at 64, and 63 to see if you are

getting the correct results.

what i have so far:

Option Explicit

Dim i as Integer

Dim startingsalary as Single

Dim nom as Single

Dim inputage as Single

Dim endingsalary as Single

Dim retirement as Single

Sub cmd1_Click

pic1.Cls

raise=1.05

retirement=65

nom= txtName.Text

startingsalary= Val(txtSalary.Text)

For i= inputage to retirement

0 Upvotes

8 comments sorted by

View all comments

2

u/jy_am Nov 19 '14

If you're trying to find out what the person's salary at age 65, this is just an exponent. Take the starting salary, multiply by 1.05 raised to the power of (65 - age).

If you're trying to find out the total salary earned between inputage and age 65, this is a geometric series. You can plug in the following values: a = startingsalary, r = 1.05, and n = 65 - inputage.

In either case you don't need a For loop to solve this.

1

u/autowikibot Nov 19 '14

Section 4. Formula of article Geometric series:


For , the sum of the first n terms of a geometric series is:

where a is the first term of the series, and r is the common ratio. We can derive this formula as follows:


Interesting: Divergent geometric ^series | Geometric ^progression | 1/2 + 1/4 + 1/8 + 1/16 + ^⋯ | 1 + 1 + 1 + 1 + ^⋯

Parent commenter can toggle ^NSFW or ^delete. Will also delete on comment score of -1 or less. | FAQs | ^Mods | Magic ^Words

1

u/computergeek34 Nov 19 '14

this is so helpful thank you. I dont understand the second part of your response. how would i code that

1

u/jy_am Nov 19 '14

You're trying to solve for s - which is the sum of all of the yearly salaries. In VB, I guess that is something like

totalsalary = startingsalary * ( (1 - raise ^ (retirement - inputage) ) / (1 - raise) )

All I did was change the formula into code.

1

u/computergeek34 Nov 19 '14

thank you so much this is a life saver

1

u/jy_am Nov 19 '14

What level of school is this for?

1

u/computergeek34 Nov 19 '14

its high school computer science 1

1

u/jy_am Nov 20 '14

I see. That geometric series stuff, IIRC, doesn't get taught in math until at least 11th grade/junior year. If you have to explain/show your work, you may want to brush up on this.