4 Replies - 5973 Views - Last Post: 17 January 2009 - 04:32 PM Rate Topic: -----

#1 bkinley  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 17-January 09

Need help converting inches-yards-feet-inches

Posted 17 January 2009 - 01:08 PM

I am new to VB and I have a simple assignment to where I need to input inches and the output will display those inches in yards, feet and inches. I am having problems with the math equation to get this too happen. Below is the code that I have thus far and thanks in advance for the help.


 Dim inches As Integer
		Dim yards As Integer
		Dim feet As Integer
		Dim total As Integer



		Console.Write("Enter a distance in inches: ")
		inches = Val(Console.ReadLine)

		total = inches / 36



		Console.WriteLine("The distance is " & total & " yards, " & total & " feet, " & total & " inches ")


		Console.Read()


Is This A Good Question/Topic? 0
  • +

Replies To: Need help converting inches-yards-feet-inches

#2 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: Need help converting inches-yards-feet-inches

Posted 17 January 2009 - 01:47 PM

How 'bout:
Dim inches As Single
Dim yards As Single
Dim feet As Single
Dim total As Single

Console.Write("Enter a distance in inches: ")
inches = Val(Console.ReadLine)

feet	= inches / 12
yards  = inches / 36

total   = inches / 36

Console.WriteLine("The distance is " & yards  & " yards, " & feet   & " feet, " & inches & " inches ")

Console.Read()


Was This Post Helpful? 0
  • +
  • -

#3 bkinley  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 17-January 09

Re: Need help converting inches-yards-feet-inches

Posted 17 January 2009 - 02:07 PM

View Postn8wxs, on 17 Jan, 2009 - 12:47 PM, said:

How 'bout:
Dim inches As Single
Dim yards As Single
Dim feet As Single
Dim total As Single

Console.Write("Enter a distance in inches: ")
inches = Val(Console.ReadLine)

feet	= inches / 12
yards  = inches / 36

total   = inches / 36

Console.WriteLine("The distance is " & yards  & " yards, " & feet   & " feet, " & inches & " inches ")

Console.Read()






Thanks for the info but it is not working like I think it is suppose to work. Let me give you an example of the output I am trying to get.

If I input 140 inches, my output should read 3 yard, 2 feet, and 8 inches.

I know I have to use the "MOD" code in order to get the remainder but I have having trouble getting the math equations to work.


Thanks
Was This Post Helpful? 0
  • +
  • -

#4 bkinley  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 17-January 09

Re: Need help converting inches-yards-feet-inches

Posted 17 January 2009 - 03:42 PM

Below is my new code but I have problems with the math adding up. The total number is not adding up to the total inches that I input.

Example:
I input 140 inches and the math gives me 3 yards, 2 feet, and 2 inches.

I know this is not correct. Is there an easier way to write out the math equation?



Module Module1

	Sub Main()
		Dim inches As Single
		Dim yards As Integer
		Dim feet As Single
		Dim total As Single

	   

		Console.Write("Enter a distance in inches: ")
		inches = Val(Console.ReadLine)


		yards = inches \ 36
		feet = inches Mod yards
		total = feet Mod inches
 

		Console.WriteLine("The distance is " & yards & " yards, " & feet & " feet, " & total & " inches ")


		Console.Read()

	End Sub

End Module


Was This Post Helpful? 0
  • +
  • -

#5 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: Need help converting inches-yards-feet-inches

Posted 17 January 2009 - 04:32 PM

		Dim inches As Integer = 140
		Dim yards As Integer
		Dim feet As Integer

		yards = inches \ 36

		inches = inches - yards * 36

		feet = inches \ 12

		inches = inches - feet * 12


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1