# Use a method to display inches as yards, feet, and inches

Page 1 of 1

## 7 Replies - 7501 Views - Last Post: 30 November 2009 - 07:53 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=142429&amp;s=15fc20e3ea82a62f07a9013a31cd2a70&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 jpt420

Reputation: 1
• Posts: 38
• Joined: 12-December 08

# Use a method to display inches as yards, feet, and inches

Posted 30 November 2009 - 02:01 PM

I am tring to write a program to display 43 inches as yards, feet and inches
ex. 67 inches is 1 yard, 2 feet and 7 inches.
This is the code I have so far:
```using System;
public class InchesToYards
{
public static void Main()
{
int inches = 67;
Console.WriteLine("43 inches is converted to:");
totalFeet(inches);
totalYards(inches);
}
public static void totalFeet(int inches)
{
int feet;
double tInches;
feet = inches / 12;
tInches = .58333 * 12;
tInches = Convert.ToInt32(tInches);
Console.WriteLine("{0} feet and {1} inches", feet, tInches);
}
public static void totalYards(int inches)
{
double feet;
int yards;
double tInches;
yards = inches / 36;
feet = .19444 * 12;
feet= Convert.ToInt32(feet);
tInches = .33328 * 12;
tInches = Convert.ToInt32(tInches);
Console.WriteLine("{0} yard {1} feet and {2} inches", yards, feet, tInches);
}
}

```

Is This A Good Question/Topic? 0

## Replies To: Use a method to display inches as yards, feet, and inches

### #2 PsychoCoder

Reputation: 1658
• Posts: 19,853
• Joined: 26-July 07

## Re: Use a method to display inches as yards, feet, and inches

Posted 30 November 2009 - 02:03 PM

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:
• Post the code you're having problems with
• Post the exact error you're receiving, if you are receiving one
• If no error explain what the code is doing versus what you want it to do
• Post your question in the body of your post, not the description field

### #3 jpt420

Reputation: 1
• Posts: 38
• Joined: 12-December 08

## Re: Use a method to display inches as yards, feet, and inches

Posted 30 November 2009 - 05:00 PM

PsychoCoder, on 30 Nov, 2009 - 01:03 PM, said:

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:
• Post the code you're having problems with
• Post the exact error you're receiving, if you are receiving one
• If no error explain what the code is doing versus what you want it to do
• Post your question in the body of your post, not the description field

I dont think that the math in the second method is right.

• Saucy!

Reputation: 6245
• Posts: 24,013
• Joined: 23-August 08

## Re: Use a method to display inches as yards, feet, and inches

Posted 30 November 2009 - 05:34 PM

```int inches = 67;
Console.WriteLine("43 inches is converted to:");
```

???

### #5 finaiized

Reputation: 0
• Posts: 84
• Joined: 29-November 09

## Re: Use a method to display inches as yards, feet, and inches

Posted 30 November 2009 - 05:53 PM

Yes, your inches variable is wrong. It should be inches= 43 instead.

### #6 jpt420

Reputation: 1
• Posts: 38
• Joined: 12-December 08

## Re: Use a method to display inches as yards, feet, and inches

Posted 30 November 2009 - 06:53 PM

finaiized, on 30 Nov, 2009 - 04:53 PM, said:

Yes, your inches variable is wrong. It should be inches= 43 instead.

oh. I changed it 43 now the problem is with the feet in the second method
```using System;
public class InchesToYards
{
public static void Main()
{
int inches = 43;
Console.WriteLine("43 inches is converted to:");
totalFeet(inches);
totalYards(inches);
}
public static void totalFeet(int inches)
{
int feet = inches / 12;
int inchesLeft = inches % 12;
Console.WriteLine("{0} Feet and {1} Inches", feet, inchesLeft);
}
public static void totalYards(int inches)
{
int yards = inches / 36;
int feet = yards / 12;  // I dont think the math is right in this part
int inchesLeft = inches % 12;
Console.WriteLine("{0} yard {1} feet and {2} inches", yards, feet, inchesLeft);
}
}

```

### #7 SixOfEleven

• Planeswalker

Reputation: 1055
• Posts: 6,643
• Joined: 18-October 08

## Re: Use a method to display inches as yards, feet, and inches

Posted 30 November 2009 - 07:06 PM

You are calculating feet wrong. What you want to do is take the number of inches minus the number of yards times 36 and then use the modulus operator with 12 to get the feet that are left over. So, if you have 43 inches and

```int feet = (inches - yards * 36) % 12;

```

### #8 jpt420

Reputation: 1
• Posts: 38
• Joined: 12-December 08

## Re: Use a method to display inches as yards, feet, and inches

Posted 30 November 2009 - 07:53 PM

Cool, thanks alot for the help