[英]What do I need to change for my code to print?
我已經創建了所有方法,但是由於某種原因,當我運行此代碼時,什么也沒有打印出來。 沒有錯誤代碼,它編譯得很好,但它只是不打印任何東西。
這是我目前正在使用的驅動程序代碼。 `
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);
}
}
`
您沒有用任何值填充list
,並且list.count
等於零。 所以 for 循環運行零次
您只需要在列表中添加一些值:
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);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.