-1

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);

            }
        }

`

caitlyn
  • 3
  • 3
  • 4
    List.Count of a new list will be zero therefore you never get inside of the loop. – Mikael Sep 09 '22 at 13:37
  • `list.Count` return always 0 because it's just created and nothing was added to – Marco Beninca Sep 09 '22 at 13:40
  • Welcome to Stack Overflow! This is a good opportunity for you to start familiarizing yourself with [using a debugger](https://stackoverflow.com/q/25385173/328193). When you step through the code in a debugger, which operation first produces an unexpected result? What were the values used in that operation? What was the result? What result was expected? Why? To learn more about this community and how we can help you, please start with the [tour] and read [ask] and its linked resources. – David Sep 09 '22 at 13:40

2 Answers2

0

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

Mahdi
  • 664
  • 3
  • 15
  • 35
0

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);
    }
}
YungDeiza
  • 3,128
  • 1
  • 7
  • 32