2016-04-28 2 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

はい、それも動作します。 –

関連する問題