Help with a problem

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Mar 2006
Posts: 14
Reputation: vickzbrit is an unknown quantity at this point 
Solved Threads: 0
vickzbrit vickzbrit is offline Offline
Newbie Poster

Help with a problem

 
0
  #1
Oct 28th, 2006
Enter the miles driven, use -1 to end:
Enter the gallons :

The miles / gallon for this tank was

Enter the miles driven, use -1 to end:
Enter the gallons used (-1 to end) :


The miles / gallon for this tank was


Enter the miles driven, use -1 to end:
Enter the gallons used (-1 to end) :

The miles / gallon for this tank was
Enter the miles driven, use -1 to end: -1

The overall average miles/gallon was

I tried to solve this above probem but i cant figure out where i m going wrong or what to do next .. can anyone please help me out with it

  1. Public Sub OverallAverage()
  2.  
  3.  
  4. Dim miles, gallons As Double
  5. Dim totalGallons As Double = 0
  6. Dim totalMiles As Double = 0
  7. Dim tank As Double = 0
  8. Dim average As Double = 0
  9.  
  10.  
  11. Console.Write("Enter the miles driven, use -1 to end: ")
  12. gallons = Console.ReadLine()
  13.  
  14. While miles <> -1
  15.  
  16. Console.Write("Enter the gallons: ")
  17. gallons = Console.ReadLine()
  18.  
  19. tank = miles / gallons
  20. Console.WriteLine("The miles / gallon for this tank was " & tank)
  21.  
  22. Console.WriteLine("Enter the miles driven, use -1 to end: ")
  23. miles = Console.ReadLine()
  24.  
  25. totalGallons = totalGallons + gallons
  26. totalMiles = totalMiles + miles
  27.  
  28. End While
  29.  
  30. average = totalMiles / totalGallons
  31. Console.Write("The overall average miles/gallon was: " & average)
  32.  
  33. End Sub
Reply With Quote Quick reply to this message  
Join Date: Dec 2002
Posts: 461
Reputation: waynespangler is on a distinguished road 
Solved Threads: 56
waynespangler waynespangler is offline Offline
Posting Pro in Training

Re: Help with a problem

 
0
  #2
Oct 28th, 2006
A couple of things:
        'you had this as gallons should be miles
        miles = Console.ReadLine()
and
            'move this to after calculate totals otherwise changing miles 
before adding to total
            'miles = Console.ReadLine()

            totalGallons = totalGallons + gallons
            totalMiles = totalMiles + miles
            miles = Console.ReadLine()
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 14
Reputation: vickzbrit is an unknown quantity at this point 
Solved Threads: 0
vickzbrit vickzbrit is offline Offline
Newbie Poster

Re: Help with a problem

 
0
  #3
Oct 28th, 2006
Thanks for pointing me out waynespangler.. i made the change for the first one you pointed me out.. but for the second one.. I am confused. If i remove

  1. miles=console.Readline()

from the top and move it to the bottom after my calculations, it asks for gallons before miles.

And to quite my program when entered -1, I have added the following code
  1. If miles >= 0 Then
  2.  
  3. average = totalMiles / totalGallons
  4. Console.WriteLine("The overall average miles/gallon was: " & average)
  5. Else
  6. Console.WriteLine("You have chose to quite by pressing -1")
  7.  
  8. End If

now.. when pressed -1, It should also show The overall average miles/gallon. I am not sure where did i make a mistake
Last edited by vickzbrit; Oct 28th, 2006 at 9:05 pm.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 14
Reputation: vickzbrit is an unknown quantity at this point 
Solved Threads: 0
vickzbrit vickzbrit is offline Offline
Newbie Poster

Re: Help with a problem

 
0
  #4
Oct 29th, 2006
alright .. i figured it out .. thankz for helping me out waynespangler
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC