2017-03-17 72 views
1

我刚刚开始学习C#编码,并且在数组上我的最新赋值问题需要输出示例中的图片,我将放入到目前为止编写的代码。我的问题是,当我运行该程序时,我在两行之间留有空格,并且这两个表格不完全对齐,是否有人知道我如何重新定位以使其看起来像样本图片?谢谢!位置C#位置文本

这是样本输出

enter image description here

int[] hrs = { 8, 24, 9, 7, 6, 12, 10, 11, 23, 1, 2, 9, 8, 8, 9, 7, 9, 15, 6, 1, 7, 6, 12, 10, 11, 23, 1, 2, 9, 8 }; 

decimal fee;           
const decimal HOURLY_RATE = 2.5m, MAX_FEE = 20;  
decimal avg = 0;           
decimal total = 0;          

Console.WriteLine("Hours Parking Fee"); 
for (int count = 0; count < hrs.Length; count++) 
{     
    Console.WriteLine("{0,3}", hrs[count]);     
    fee = hrs[count] * HOURLY_RATE;    
    if (fee > MAX_FEE) 
    { 
     fee = MAX_FEE; 
    } 
    Console.WriteLine("{0,13}", fee.ToString("C")); 
    // calculate average fee paid      
    { 
       total = total + fee; 
    } 
} 
avg = total/30;  //average = total/30;     
Console.WriteLine("average parking fee: " + avg.ToString("C")); 
Console.ReadKey(); 
Console.ReadKey(); 
+0

你知道Console.WriteLine与Console.Write之间的区别? – Mick

+0

我再次看到那个谢谢,仍然让我的头只在这个只有5周 – Viper010

+0

无后顾之忧。祝你好运。 – Mick

回答

1

您正在使用的WriteLine这将增加在新线的入口,它的更好,如果你把你的输出和打印

for (int count = 0; count < hrs.Length; count++) 
     {  
      //Console.WriteLine("{0,3}", hrs[count]); 
      fee = hrs[count] * HOURLY_RATE; 
      if (fee > MAX_FEE) 
      { 
       fee = MAX_FEE; 
      } 
      //Console.Write("{0,13}", fee.ToString("C")); 

      Console.WriteLine("{0,3} {1,13}", hrs[count], fee.ToString("C")); 

      // calculate average fee paid      
      { 
       total = total + fee; 
      } 
     } 
+0

非常感谢您的帮助! – Viper010

+0

如果能帮助 – AKN

+0

完成再次感谢,请您将其标记为ANSWER! – Viper010