Hey all, i am a newbie at C# and need help with this program. This is what i have so far.The first part of the program work, but the second method InchesToFeetdoes not work. Please help. Due on Monday.


Create a class named InchesToFeet. Its Main ( ) method holds an integer variable
named inches to which you will assign a value. Create a method to which you pass inches. The method displays inches in feet and inches. For example, 67 inches is 5 feet 7 inches. Save the program as InchesToFeet.cs.

b. Add a second method to the InchesToFeet class. This method displays a passed
argument as yards, feet, and inches. For example, 67 inches is 1 yard, 2 feet, and 7 inches. Add a statement to the Main ( ) method so that after it calls the method to convert inches to feet and inches, it passes the same variable to the new method to convert the same value to yards, feet, and inches. Save the program as InchesToYards.cs

using System;
class InchesToFeet
{
    static void Main()
    {
        //Declare variable
        int inches = 43;

        //output to the screen
        Console.WriteLine("67 inches is ");
        totalFeet(inches);
        Console.ReadLine();
    }
    //Method to pass inches
    public static void totalFeet(int inches)
    {
        //Calculation conversion for feet and 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; 
       double yards; 
       double tInches;
        yards = .02777;
       yards = Convert.ToInt32(yards);
        yards = (.58333 - .02777 * 36) % 12;
        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); 
    }
}

Where did this tInches from from?? That doesn't rely on input from the user at all, so it begs the question, what is it doing??

Also, saying 67 inches is:

and then using 43 inches in your calculations doesn't make any sense man!!

Dude thats a mess!

Tell me in plain english what you want to achieve and I'll code it for you along with some explanation of good practice - eg classes should be named after nouns - eg Car, Person, Animal, Customer and the operations or methods should be named after verbs eg customer.Sell() or customer.Pay() and so on

Also your methods should not use Console as then they are tied to Console programs - you could not reuse your code in other apps - eg WinFroms or Webapps.

Better to have conversion methods return just the value and then output it to the Console from the main program or client code.

Remove line 10
Rename the method on line 11 to InchesToFeet your assignment tells you to do so, why not do it then?
Line 23 should read: Console.WriteLine("{0} inches is: {1} feet and {2} inches", inches,feet, tInches);

I know my program is a mess because i donot know what i am doing. That is why i need help.This is what the program should do.

a.Create a class named InchesToFeet. Its Main ( ) method holds an integer variable
named inches to which you will assign a value. Create a method to which you pass inches. The method displays inches in feet and inches. For example, 67 inches is 5 feet 7 inches. Save the program as InchesToFeet.cs.

b. Add a second method to the InchesToFeet class. This method displays a passed
argument as yards, feet, and inches. For example, 67 inches is 1 yard, 2 feet, and 7 inches. Add a statement to the Main ( ) method so that after it calls the method to convert inches to feet and inches, it passes the same variable to the new method to convert the same value to yards, feet, and inches. Save the program as InchesToYards.cs

Hi

Ok sorry for saying its a mess, just being honest!

Is there any flexibility in these instructions. I wouldn't want to put a Main method in the InchesToFeet class as then this class is difficult to reuse.

If there is no flexibility and you have to do exactly as told I will happily code this for you.

Thank you for the help. But it has to be done as the question says.

Ok leave it with me and I'll have a look later today. Is this quick enough or is this due today?

this is due at 9 a.m. this morning.

Ahh sorry can't help then - literally just off to work in 1 minute. Very sorry.

Ok. but would still like to have the program for future reference when you have a chance to look at it later today.

Thanks.

Ok I'm at work now - maybe you have time to get this in - I did this quickly in a few minutes so its not up to my usual standards - lacks error checking and commnents etc but maybe it will help in time?

using System;

class InchesToFeet
{
    static void Main()
    {
        //Declare variable
        int inches = 49;

        //output to the screen
        Console.WriteLine(inches.ToString() + " inches is ");
        
        TotalFeet(inches);

        TotalYards(inches);
        
        Console.ReadLine();
    }

    //Method to pass inches
    public static void TotalFeet(int inches)
    {
        //Calculation conversion for feet and inches
        int feet;

        int tInches;
        
        feet = inches / 12;

        tInches = inches % 12;
        
        Console.WriteLine("{0} feet and {1} inches", feet, tInches);
    }

    public static void TotalYards(int inches)
    {
        int feet;
        int tfeet;
        int yards;
        int tInches;

        feet = inches / 12;

        yards = feet / 3;

        tfeet = feet % 3;

        tInches = inches % 12;

        Console.WriteLine("{0} yard {1} feet and {2} inches", yards, tfeet, tInches);
    }
}

Thank you sooooo much.

You rock

No probs

Any other issues give me a shout

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.