2016-04-28 90 views
0

這是我的主要方法不能獲得方法寫入正確的輸出文件和無法編輯

static void Main() 
    { 
     int id, age, exp; 
     double avgAge, avgExp, ageSum = 0, expSum = 0, empSum = 0; 
     char type; 
     double total = 0; 

     OpenFiles(); 
     PrintReportHeadings(); 
     while ((lineIn = fileIn.ReadLine()) != null) 
     { 
      empSum++; 
      ParseLineIn(out id, out type, out age, out exp); 
      UpdateTotals(ref ageSum, ref expSum, age, exp); 
      string eligibility = GetEligibility(type, age, exp); 
      PrintDetailLine(id, type, age, exp, eligibility); 

     } 

     avgAge = CalcAvg(ageSum, empSum, out total); 
     avgExp = CalcAvg(expSum, empSum, out total); 
     PrintAvg(avgAge, avgExp); 
     CloseFiles(); 
    } 

這裏是我的PrintAvg方法:

static void PrintAvg(double avgAge, double avgExp) 
    { 
     fileOut.Write("\nAvg\t {0:f1} {1:f1}", avgAge, avgExp); 
    } 

而且在VisualStudio中

Employee Report    

ID Age Exp Eligibility 
---- --- --- ----------- 
1235 45 20 lack of exp age 
2536 55 21 lack of exp age 
5894 60 30 lack age 
4597 75 35 can retire 
2597 35 10 lack of exp age 
5689 40 20 lack of exp age 
5489 55 39 lack age 
5872 60 40 can retire 
5569 55 25 can retire 
5566 80 20 lack of exp 
8865 59 35 can retire 
5598 65 35 can retire 
我的輸出文件

然後我再次輸出文件在記事本中...

  Employee Report    

ID Age Exp Eligibility 
---- --- --- ----------- 
1235 45 20 lack of exp age 
2536 55 21 lack of exp age 
5894 60 30 lack age 
4597 75 35 can retire 
2597 35 10 lack of exp age 
5689 40 20 lack of exp age 
5489 55 39 lack age 
5872 60 40 can retire 
5569 55 25 can retire 
5566 80 20 lack of exp 
8865 59 35 can retire 
5598 65 35 can retire 
Avg 57.0 27.5 

記事本顯示的平均值,當我編輯PrintAvg方法試圖獲得一個換行降低平均線下來,它沒有任何效果。我該如何解決?

+0

爲什麼不使用WriteLine? –

+0

我確實繼續並使用 –

+0

是你的問題解決?我可以發表一個答案嗎? :) –

回答

1

Windows使用\ r \ n作爲換行符。所以,也許你應該嘗試寫\ r \ n來獲得你想要的換行數。

static void PrintAvg(double avgAge, double avgExp) 
{ 
    fileOut.Write("\r\nAvg\t {0:f1} {1:f1}", avgAge, avgExp); 
} 
+1

甚至更​​好:Environment.NewLine –

+0

是的,這也會起作用。 –