Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,092 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,815 people online right now. Registration is fast and FREE... Join Now!




Help with Visual Basic 2005

 
Reply to this topicStart new topic

Help with Visual Basic 2005, 12 Days of Christmas

collegegirl
23 Apr, 2008 - 09:05 AM
Post #1

New D.I.C Head
*

Joined: 23 Apr, 2008
Posts: 2

[font=Book Antiqua][size=2][size=4]
I am still new to the whole Visual Basic thing, but I can't figure this stupid program out for the life of me. Its for repetition. The question states the following: The 12 days of Christmas. Each Year, PNC Advisors of Pittsburgh Publishes a Christmas price list. Write a program that requests an integer from 1 through 12 and then lists the gifts for that day along with that day's cost. On the nth day, the n gifts are 1 partride in a pear tree, 2 turtle doves,..., n of the nth item. The program also should give the total cost of all twelve days.
Then a table is given:
Partridge in a pear tree 104.99
Turtle Dove 20.00
French Hen 15.00
Calling Bird 99.99
Gold Ring 65.00
Geese-a-Laying 50.00
Swan-a-Swimming 600.00
Maid-a-Milking 5.15
Lady Dancing 508.46
Lord-a-Leaping 403.91
Piper Piping 186.65
Drummer Drumming 186.36

Example:
The gifts for day 3 are
1 Partridge in a pear tree
2 Turtle Dove
3 French Hen
Cost: 189.99
Total Cost for the 12 days: 72,608.00

I have no idea what I am doing, someone please help!
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Help With Visual Basic 2005
23 Apr, 2008 - 09:24 AM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,660



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Well when you see a problem like this a few things should come to mind automatically.... since it is a list, you will probably need an array to hold the list. Probably two arrays since you have one list of the item and another for their price (these will be parallel arrays where item 0 in the first array is your partridge and item 0 is the price of the partridge in the second array). Since you are asked to move through the list, you are obviously going to need a loop of some sorts. Since you are asked to loop through a range (like 1 to N) that loop will probably be a for loop since that is the loop designed for ranged looping. Lastly, you are asked to keep track of two sums, the one for the total list and one for all items up to a given day. So you will need two variables to hold sums.

So right there you have the major pieces you are going to need. So the next step is to plan out how to solve this using the pieces up top... this is where you write your steps.

CODE

1) Create and initialize an array to hold the item names.
2) Create and initialize an array to hold the item prices (same order as the item names).
3) Prompt user for an integer and check to make sure it is 1 - 12
     3a.) Subtract 1 from their choice because arrays are 0 index
     3b.) Setup your two variables used for holding sums. Since these are prices, you will want to use a double.
     3c.) Setup a for loop to go through the entire set of days
          3c1.) For each item check to make sure this day is in the range of days they specified. If so, print the item from one list and add that price to your first sum variable.
          3c2.) Despite being in their range or not, you are going to add the price to the other sum variable.
4) When the loop is finished you will have printed the items up to the nth day, added those days to the first sum variable, added every item to the second variable and so all is left is to print the cost (your first sum variable) and the total cost for all 12 days (the second sum variable).


Now these may appear to be a lot of steps, but the code itself is going to be fairly short. The loop is going to have about 3 to 5 lines in it and the whole program will probably be around 50 lines or so.

Once you get some stuff started, show what you have back here and we can help guide you further. smile.gif

User is offlineProfile CardPM
+Quote Post

collegegirl
RE: Help With Visual Basic 2005
23 Apr, 2008 - 09:28 AM
Post #3

New D.I.C Head
*

Joined: 23 Apr, 2008
Posts: 2

CODE
Public Class Form1

    Private Sub btnchristmas_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnchristmas.Click
        Dim item As String
        Dim itemCost, dayCost, totalCost, totalcostItems, totaldayCost, PartialdayCost As Double
        Dim Daynum, NumDay As Integer

        DIm sr As IO.StreamReader-IO.File.OpenText("Christmas.txt")

        CInt(Me.txtday.Text)

        dayCost = Daynum * itemCost
        totalCost += totalcostItems
        totalCost = CDbl(sr.Readline)

      For Daynum 1 through 12





    End Sub
End Class

This is the code that I have so far. It's not a lot, but that's all I got
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Help With Visual Basic 2005
23 Apr, 2008 - 09:33 AM
Post #4

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,660



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Oh I forgot you are reading from a file, that is going to make the job even easier. Instead of loading arrays, you just read the file line by line. Fantastic.

As for your code, remember you are going to do most of your calculations in the loop as you read from the file. Read in a line, add to your sums, print the item, go to next item.

So give it a try with that philosophy in mind. smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 12:02AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month