What do I need to change for my code to print?

Viewed 30

I have created all the methods but for some reason when I run this code nothing prints. There are no error codes, it compiles fine but it just doesn't print anything.

This is the driver code I am currently using. `

public static void Main(string[] args)
        {
            
            Tree tree = new Tree(0);
            List<double>  list = new List<double>();
            for (int i= 0; i < list.Count; i++)
            {  double rain=   Driver.inchesRain(list);
                double rainMM= Driver.inchesToMM(rain);

                Console.WriteLine("Year " + i);
     
                Console.WriteLine("Rain this year: " + rain+" inches or "+rainMM +"mm");
                tree.grow(list[i]);
                tree.drawMe();
                Driver.fire(tree, list);

            }
        }

I have also tired to format it like this but this doesn't work either

 public static void Main(string[] args)
        {
            
            Tree tree = new Tree(0);
            List<double>  list = new List<double>();
            for (int i= 0; i < list.Count; i++)
            { 
                Console.WriteLine("Year " + i);
                Console.WriteLine("Rain this year: " +  Driver.inchesRain(list)+" inches or "+Driver.inchesToMM(rain) +"mm");
                tree.grow(list[i]);
                tree.drawMe();
                Driver.fire(tree, list);

            }
        }

`

2 Answers

You doesn't fill list with any value and list.count equals zero. So for loop runs for zero times

You just need to add some values to the list:

public static void Main(string[] args)
{
    Tree tree = new Tree(0);
    List<double>  list = new List<double>() {1.2, 2.3, 5.5}; //values added here
    
    for (int i= 0; i < list.Count; i++)
    {  double rain=   Driver.inchesRain(list);
        double rainMM= Driver.inchesToMM(rain);

        Console.WriteLine("Year " + i);

        Console.WriteLine("Rain this year: " + rain+" inches or "+rainMM +"mm");
        tree.grow(list[i]);
        tree.drawMe();
        Driver.fire(tree, list);
    }
}
Related