Need VB 6.0 help

Discussion in 'OT Technology' started by HarryHd, Mar 1, 2003.

  1. HarryHd

    HarryHd Guest

    I working on a vb assignment and I'm alittle stuck. Hopefully someone can give me some help.

    Heres the assignment:

    The Twelve Days of Christmas. Each year, Provident National Bank of Phily publishes a Christmas price list. Write a program that requests an integer from 1 to 12 and then lists the gifts for that day along with that days's cost. On the nth day, the n gifts are 1 partridge in a pear tree, 2 turtle doves,...n of the nth item. The program also should give the total cost of all twelve days. Here is an example for a user that enters 3

    The gifts for day 3 are
    1 partridge in a pear tree
    2 turtle doves
    3 French hens
    Cost: $92.50

    I have set up the Do While loop for the days. But, my problem is setting up the code to add each gifts price and showing the total. I've tried different things but the closest I've come is showing the price for each individual item. Keep in mind that the price for each item is also multiplied by the day. Ex. 2 turtle doves = 2 * $25. Can anyone help me figure this out? :bigthumb:
  2. HarryHd

    HarryHd Guest

    This is what I have so far:

    Private Sub cmdDisplay_Click()
    Dim day As Single, gift As String, price As Single
    Dim total As Single
    'Display total price of gifts
    day = Val(txtDay.Text)
    picOutput.Print "The gifts for day"; day; "are"
    Open App.Path & "\GIFTS.txt" For Input As #1
    Do While Not EOF(1)
    Input #1, gift, price, nom
    If nom <= day Then
    picOutput.Print Tab(2); gift
    End If
    Close #1

    Open App.Path & "\GIFTS.txt" For Input As #1
    Input #1, gift, price, nom
    If nom <= day Then
    total = price * nom
    picOutput.Print total
    End If
    End Sub

    It only works when I enter 1 and thats it.
  3. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Mar 14, 2000
    Likes Received:
    Vancouver, BC, CANADA
    Well, seeing how I don't have all of the info, I can tell you that running totals are generally coded like this:

    total = total + price * nom

    and this can be added into the first loop without any problems, simply don't print it until the loop is completely done.

Share This Page