Jump to content

Stuck on a project and need help pls !!!

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
aalicea87

aalicea87

    Newbie

  • Members
  • Pip
  • 1 posts
Attached is a pdf version of my final project, it is suppose to double your money as the days goes by...however i am stuck instead of my code looking like :

Day1-.01 cent
Day2-.02 cent
Day3-.04 cent
Day4-.08 cent
Day5-.16 cent

My code looks like:

Day1-.02 cent
Day2-.04 cent
Day3-.06 cent
Day4-.08 cent
Day5-.10 cent

What is wrong with my code? Can anyone explain to me the right method in what i am doing wrong and need to do.. I'm fairly new at programming and this project been breaking my head all day. Any help will be greatly appreciated

Public Class Form1

'Constant for Starting amount
Const dblPenny As Double = 0.01
Const dblNickel As Double = 0.05
Const dblDime As Double = 0.1
Const dblQuater As Double = 0.25


Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
' Declare ounlocal variables
Dim dblPay As Double
Dim intcount As Integer
Dim pay As Decimal
Dim Total As Decimal
Dim decTotal As Decimal
Dim perString As String = 0
lstOutput.Items.Clear()
Dim numDays As Integer = 0

Try

'Getting the starting amount
If radPenny.Checked = True Then
dblPay = dblPenny
ElseIf radNickel.Checked = True Then
dblPay = dblNickel
ElseIf radDime.Checked = True Then
dblPay = dblDime
ElseIf radQuater.Checked = True Then
dblPay = dblQuater

End If


'Getting the Duration
If radThirty.Checked = True Then
numDays = 30
ElseIf radSixty.Checked = True Then
numDays = 60
ElseIf radNinety.Checked = True Then
numDays = 90
ElseIf radOneTwenty.Checked = True Then
numDays = 120

End If

'Calculating the pay

Do While intcount < numDays

intcount += 1
decTotal += 2 * dblPay
perString = decTotal.ToString("c")
lstOutput.Items.Add("Day " & intcount & " your pay is " & perString)

Loop

Catch
End Try

#2
Bound

Bound

    Learning Programmer

  • Members
  • PipPipPip
  • 30 posts
Hi aalicea87,

Using code tags greatly increases your code's readability on here. :)

I think the reason you start off with your amount already doubled is because of this line:


decTotal += 2 * dblPay


You double the amount right away instead of waiting for the first amount to be displayed. Perhaps you could print the value of "dblPay" right before the Do loop is activated like this:


lstOutput.Items.Add("Day " & intcount & " your pay is " & perString)


And in your dimensioning of "intcount" up here:


Dim intcount As Integer


You could use:


Dim intcount As Integer = 1


So that way it'll print Day 1 instead of Day 0. :) Just a thought, but perhaps I'm incorrect.