So I can't seem to get an else if to work right.

What I've been doing is writing a unit converter to try and teach myself the basics of programming, I'm kind of new to it. So new as to say this is actually my first working while loop. So I've been writing the code, and then doing as a friend who is somewhat more experienced at programming has told me to do. Which is separate said code out into methods. I used the VS2010 automatic method making thing for this, because I didn't know how to do it myself. The full source code in question is here <http://pastebin.com/9mZPPtWr> the problem bit is this one 

` 

```
      else if (type == "cups")

      {

        Console.WriteLine("Enter a number of liters to be converted into cups.");
        amount = Convert.ToDouble(Console.ReadLine());
        Console.WriteLine(cupsTolitConverter.Convert(amount) + " cups to said number of liters.");

      }`

```

I entered cups into the console, and despite every other entry/imput working fine and the loop looping back to the selection bit each time, I can't seem to get that section of code to work. It just won't display, I've been working on it for an hour now, and I starting to think I'm missing something incredibly obvious, or something incredibly arcane. Also I have a lot of repeated code and I was wondering if there was a way to simplify that down to less repeats.

Thanks, and I hope that was readable and understandable. Even if my code probably isn't. Also I got the starting code(the top bit) from Accelerated C#. Will elaborate more on my question if needed.
['https://Stackoverflow.com/questions/12100977', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1620762/']
First of all: You have error in line 141. Delete that `done` word. I suggest it was just copy paste mistake. Second of all: Here you say your code is:

```
else if (type == "cups")

      {

        Console.WriteLine("Enter a number of liters to be converted into cups.");
        amount = Convert.ToDouble(Console.ReadLine());
        Console.WriteLine(cupsTolitConverter.Convert(amount) + " cups to said number of liters.");

      }

```

But in the solution you gave link to there is:

```
else if(type == "cups")
                    {

                        Console.WriteLine("Enter a number of liters to be converted into cups.");
                        amount = Convert.ToDouble(Console.ReadLine());
                        Console.WriteLine(cupsTolitConverter.Convert(amount) + " centimeters to said number of inches.");

                    }

```

I suggest it is just inattention. Your code work fine, just replace 

```
Console.WriteLine(cupsTolitConverter.Convert(amount) + " centimeters to said number of inches.");

```

with

```
Console.WriteLine(cupsTolitConverter.Convert(amount) + " cups to said number of liters.");

```

in your solution. 

Talking about simplifying your code, and removing repeatings. Of course there is way to do that. That procedure is called code-refactoring. For example you wrote in your project:

```
...
else if(type == "grams")
                    {

                        amount = gramsToOunces(ozToGramsConverter, ref done);

                    }
...

```

Evaluation of `amount` you replaced to gramsToOunces() method. This is code refactoring too in some measure. You shoul take common parts of your code and look what they depending of. For example:

```
private static double MilesToFeet(UnitConverter milesToFeetConverter, ref int done)
        {

            double amount;
            Console.WriteLine("Enter a number of miles to be converted to feet.");
            amount = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine(milesToFeetConverter.Convert(amount) + " feet to said number of miles.");

            return amount;

        }

```

Every your convert method has such structure. In every method you do the same. You print the same instruction message... you declare the same amount variable and set it's value to console input... And you write almost the same information message after. All of this instead on N methods you have you can put in ONE method. First of all you should extend your converter class. Add two more string fields fields. `FromUnit` and `ToUnit`. Why??? Because you give converter instance as a parameter to your method. And you can use this instance for storing more information about this converter, and for creating information message after. For example:

```
public class UnitConverter
    {
        double ratio;
        public string From { get; set; }
        public string To { get; set; }
        public UnitConverter(double unitratio) { ratio = unitratio; }
        public double Convert(double unit) { return unit * ratio; }
    }

```

Than, when you create instance of converter, set appropriate values for these properties. 

```
UnitConverter milesToFeetConverter = new UnitConverter(5280) { From = "miles" , To = "feet"};

```

Now let's write a method which will be represantation of all of your already created methods (gramsToOunces, kilometersToMiles and so on);

```
private static void MakeConversion(UnitConverter customConverter)
        {
            Console.WriteLine("Enter a number of {0} to be converted to {1}.",customConverter.From, customConverter.To);
            double amount = Convert.ToDouble(Console.ReadLine());
            string message = string.Format("{0} {1} to said number of {2}", amount, customConverter.To, customConverter.From);
            Console.WriteLine(message);
        }

```

and now you can remove ALL of your methods and in if blocks you can call this one method, just with different parameters instead of calling different methods, which do the same.

else if(type == "miles")
 {
 MakeConversion(milesToFeetConverter);
 }

After all these manipulation your solution will look like:

```
using System;

namespace ConsoleApplication2
{
    public class UnitConverter
    {
        double ratio;
        public string From { get; set; }
        public string To { get; set; }
        public UnitConverter(double unitratio) { ratio = unitratio; }
        public double Convert(double unit) { return unit * ratio; }
    }

    class Test
    {
        private static void MakeConversion(UnitConverter customConverter)
        {
            Console.WriteLine("Enter a number of {0} to be converted to {1}.",customConverter.From, customConverter.To);
            double amount = Convert.ToDouble(Console.ReadLine());
            string message = string.Format("{0} {1} to said number of {2}", amount, customConverter.To, customConverter.From);
            Console.WriteLine(message);
        }

        public static void Main()
        {                 
            UnitConverter feetToInchesConverter = new UnitConverter(12) { From = "feet", To = "inches"};
            UnitConverter milesToFeetConverter = new UnitConverter(5280) { From = "miles" , To = "feet"};
            UnitConverter kmsToMilesConverter = new UnitConverter(1.609) { From = "kilometers", To = "miles"};
            UnitConverter centToInchesConverter = new UnitConverter(2.54) { From = "centimeters", To = "inches" };
            UnitConverter ozToGramsConverter = new UnitConverter(28.349) { From = "ounces", To = "grams" };
            UnitConverter cupsTolitConverter = new UnitConverter(4.226) { From = "cups", To = "litters" };

            string type;
            int done;

            done = 0;

            while(done == 0)
            {
                {
                    type = Console.ReadLine();

                    if(type == "centi")
                    {
                        MakeConversion(centToInchesConverter);
                    }

                    else if(type == "feet")
                    {
                        MakeConversion(feetToInchesConverter);
                    }

                    else if(type == "km")
                    {
                        MakeConversion(kmsToMilesConverter);
                    }

                    else if(type == "miles")
                    {
                        MakeConversion(milesToFeetConverter);
                    }

                    else if(type == "grams")
                    {
                        MakeConversion(ozToGramsConverter);
                    }

                    else if(type == "cups")
                    {
                        MakeConversion(cupsTolitConverter);
                    }

                    else if(type == "end")
                    {
                        done = 1;
                    }
                }
            }
        }
    }
}

```

Of curce you can do more a lot of things to make code easier and clearer. Replace if with cases, replace `MakeConversion` method directly to UnitConverter class, change architecture of your class. It is only my suggestions about what you can do. But first of all try to learn how to write your oun methods and classes, and don't use VisualStudio method generator, you should know how to write methods yourself. I somehow tried to explain that, hope it helped
I ran your code and (after fixing a simple error) it correctly enters the *else if* that you reference.

You may want to echo back what you type in to make sure you are not mistyping your input.

The error was that you have

> 
> done
> 
> 
> 

on a line by itself. Presumably you meant to assign a value.