7 Replies - 4677 Views - Last Post: 30 November 2009 - 07:53 PM Rate Topic: -----

#1 jpt420  Icon User is offline

  • New D.I.C Head

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

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

Post icon  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);
		Console.ReadLine();
	}
	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  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • 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

Was This Post Helpful? 0
  • +
  • -

#3 jpt420  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • 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

View PostPsychoCoder, 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.
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6092
  • View blog
  • Posts: 23,612
  • 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:");

???
Was This Post Helpful? 1
  • +
  • -

#5 finaiized  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#6 jpt420  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • 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

View Postfinaiized, 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);
		Console.ReadLine();
	}
	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);
	}
}


Was This Post Helpful? 0
  • +
  • -

#7 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 945
  • View blog
  • Posts: 6,342
  • 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;


Was This Post Helpful? 1
  • +
  • -

#8 jpt420  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1