| | |
Help with a problem
Please support our VB.NET advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Mar 2006
Posts: 14
Reputation:
Solved Threads: 0
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
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
VB.NET Syntax (Toggle Plain Text)
Public Sub OverallAverage() Dim miles, gallons As Double Dim totalGallons As Double = 0 Dim totalMiles As Double = 0 Dim tank As Double = 0 Dim average As Double = 0 Console.Write("Enter the miles driven, use -1 to end: ") gallons = Console.ReadLine() While miles <> -1 Console.Write("Enter the gallons: ") gallons = Console.ReadLine() tank = miles / gallons Console.WriteLine("The miles / gallon for this tank was " & tank) Console.WriteLine("Enter the miles driven, use -1 to end: ") miles = Console.ReadLine() totalGallons = totalGallons + gallons totalMiles = totalMiles + miles End While average = totalMiles / totalGallons Console.Write("The overall average miles/gallon was: " & average) End Sub
•
•
Join Date: Dec 2002
Posts: 461
Reputation:
Solved Threads: 56
A couple of things:
and
'you had this as gallons should be miles
miles = Console.ReadLine()'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()
•
•
Join Date: Mar 2006
Posts: 14
Reputation:
Solved Threads: 0
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
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
now.. when pressed -1, It should also show The overall average miles/gallon. I am not sure where did i make a mistake
VB.NET Syntax (Toggle Plain Text)
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
VB.NET Syntax (Toggle Plain Text)
If miles >= 0 Then average = totalMiles / totalGallons Console.WriteLine("The overall average miles/gallon was: " & average) Else Console.WriteLine("You have chose to quite by pressing -1") 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.
![]() |
Similar Threads
- Problem with Windows Update and WinXP (Web Browsers)
- Installing Windows 98 On VMware. Floppy problem (Windows 95 / 98 / Me)
- Windows XP keeps restarting since a new video card (Windows NT / 2000 / XP)
- Redhat Linux 6.2 - ipop3d problem? (*nix Software)
- Problem with T720 (Cellphones, PDAs and Handheld Devices)
- Connection Problems (Networking Hardware Configuration)
- Encoding (Unicode) problem in IE 6.0 (Web Browsers)
- .htaccess mod_rewrite problem (Linux Servers and Apache)
- Javascript/HTML problem!!! (JavaScript / DHTML / AJAX)
Other Threads in the VB.NET Forum
- Previous Thread: need help
- Next Thread: key in data in console...
Views: 1340 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for VB.NET
"crystal .net .net2005 2008 access add application array assignment basic box button buttons center class click code combo convert cpu data database datagrid datagridview design designer dissertation dissertations dissertationthesis dosconsolevb.net editvb.net employees error excel exists firewall function image images isnumericfuntioncall listview login map math memory mobile module msaccess mssqlbackend mysql navigate net opacity page pan picturebox port print printing printpreview problem record refresh regex reports" reuse right-to-left save savedialog search serial socket sorting sql sqldatbase storedprocedure string structures studio temp textbox timer txttoxmlconverter upload useraccounts usercontol usercontrol vb vb.net vb.nettoolboxvisualbasic2008sidebar vb2008 vbnet vista visual visualbasic visualbasic.net visualstudio2008 web wpf xml





.. thankz for helping me out 