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()

# Need help converting inches-yards-feet-inches

Page 1 of 1## 4 Replies - 8272 Views - Last Post: 17 January 2009 - 04:32 PM

### #1

# 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.

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

### #2

## 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()

### #3

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

Posted 17 January 2009 - 02:07 PM

n8wxs, 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

### #4

## 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?

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

### #5

## 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

Page 1 of 1