What's new

For...next Loops

  • Thread starter Andzrej
  • Start date
  • Views 520
Andzrej

AndzrejGFX

Contributor
Hardened Veteran Grammar Nazi Mr. Nice Guy
Messages
2,968
Reaction score
332
Points
365
Sin$
0
Hey guys, I'm stuck with a problem.
The assignment is to allow the user to enter in a number from 1 - 12 and determine what the
total price of that day's Christmas gifts will be.

The input file data shown in the book would be as follows:
Code:
"partridge in a pear tree", 27.50 
"turtle doves", 25 
"French hens", 5 
"calling birds", 70 
"gold rings", 60 
"geese-a-laying", 25 
"swans-a-swimming", 1000 
"maids-a-milking", 4.25 
"ladies dancing", 289.50 
"lords-a-leaping", 292.50 
"pipers piping", 95.75 
"drummers drumming", 95

Items for this project:
• The name of the input file will be called Christmas.txt. Please hardcode the name into your Open
statement.
• The amounts for the items in the input file are each items. So, for example, if it is day five, the
cost per day would be:

$27.50 (the price of a partridge in a pear tree)

+ $50.00 (the price of two turtle doves)

+ $15.00 (the price of three French Hens)

+ $280.00 (the price of four calling birds)

+ $300.00 (the price of five golden rings)


$672.50 total for 5 days

• The processing to determine the day's gift cost must be done with a For..Next loop. There will
be no If statements in the cost determination processing.

Nor will you use an IfElse structure or a Select Case structure, or anything else to make
decisions. The only processing that will be accepted will be a For..Next loop!!

My dilemma is getting the processing to work with for..next statements.
Can anyone help me with this? It would be greatly appreciated :smile:
 
Cmitch55

Cmitch55

Enthusiast
Messages
1,570
Reaction score
75
Points
160
Sin$
0
Hey guys, I'm stuck with a problem.
The assignment is to allow the user to enter in a number from 1 - 12 and determine what the
total price of that day's Christmas gifts will be.

The input file data shown in the book would be as follows:
Code:
"partridge in a pear tree", 27.50 
"turtle doves", 25 
"French hens", 5 
"calling birds", 70 
"gold rings", 60 
"geese-a-laying", 25 
"swans-a-swimming", 1000 
"maids-a-milking", 4.25 
"ladies dancing", 289.50 
"lords-a-leaping", 292.50 
"pipers piping", 95.75 
"drummers drumming", 95

Items for this project:
• The name of the input file will be called Christmas.txt. Please hardcode the name into your Open
statement.
• The amounts for the items in the input file are each items. So, for example, if it is day five, the
cost per day would be:

$27.50 (the price of a partridge in a pear tree)

+ $50.00 (the price of two turtle doves)

+ $15.00 (the price of three French Hens)

+ $280.00 (the price of four calling birds)

+ $300.00 (the price of five golden rings)


$672.50 total for 5 days

• The processing to determine the day's gift cost must be done with a For..Next loop. There will
be no If statements in the cost determination processing.

Nor will you use an IfElse structure or a Select Case structure, or anything else to make
decisions. The only processing that will be accepted will be a For..Next loop!!

My dilemma is getting the processing to work with for..next statements.
Can anyone help me with this? It would be greatly appreciated :smile:

I'll start this now seeing as im bored as hell but someone may come in with the answer before me
 
Andzrej

AndzrejGFX

Contributor
Hardened Veteran Grammar Nazi Mr. Nice Guy
Messages
2,968
Reaction score
332
Points
365
Sin$
0
I'll start this now seeing as im bored as hell but someone may come in with the answer before me

You don't have to do it for me if you don't want to, pseudocode or explaining how to make the processing work would be enough.
 
Cmitch55

Cmitch55

Enthusiast
Messages
1,570
Reaction score
75
Points
160
Sin$
0
You don't have to do it for me if you don't want to, pseudocode or explaining how to make the processing work would be enough.
you can't use anything but for next or you use for next with other things?
 
Cmitch55

Cmitch55

Enthusiast
Messages
1,570
Reaction score
75
Points
160
Sin$
0
This does it for the first one same concept for the other 11


Code:
 Dim intResponse As Integer

intResponse = InputBox("Enter a number")
For intJ = 1 To intResponse
For intResponse = 1 To 1
Print "partridge in a pear tree", 27.5
Next intResponse
Next intJ



End Sub

Edit: this actually isn't right 100 percent but if you mess around with this you should be able to figure the right answer
 
Andzrej

AndzrejGFX

Contributor
Hardened Veteran Grammar Nazi Mr. Nice Guy
Messages
2,968
Reaction score
332
Points
365
Sin$
0
This does it for the first one same concept for the other 11


Code:
 Dim intResponse As Integer

intResponse = InputBox("Enter a number")
For intJ = 1 To intResponse
For intResponse = 1 To 1
Print "partridge in a pear tree", 27.5
Next intResponse
Next intJ



End Sub

Edit: this actually isn't right 100 percent but if you mess around with this you should be able to figure the right answer

Thanks!! I figured it out.
Code:
intResponse = Val(txtDays.Text)
For i = 1 To intResponse
For j = 1 To intResponse
Input #1, strName, sngCost
sngTotalCost = sngTotalCost + (sngCost * i)
picShow.Print i; strName
i = i + 1
Next j
Next i
picShow.Print "Cost:"; Tab(7); FormatCurrency(sngTotalCost)
End If
 
Top Bottom
Login
Register