성적표

PUBLISHED
POSTED IN COMPUTING
개요 :
1. 3명의 이름과 국어, 영어, 수학 점수를 입력받는다.
2. 가로줄의 평균을 마지막 에 출력한다.
3. 마지막 줄은 국어, 영어, 수학의 평균을 출력한다.

Code :
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace Homwork1
{
  public struct InputData
  {
       public string name;
       public int korScore;
       public int engScore;
       public int mathScore;
       public int sE;
  }
  class Program
  {
       static void Main(string[] args)
       {
           List<InputData> iData = new List<InputData>();
           InputData iP = new InputData();
           int korS=0;
           int engS=0;
           int mathS=0;
           for (int i = 0; i < 3; i++)
           {
               Console.Write("이름을 입력하세요 : ");
               iP.name = Console.ReadLine();
               Console.Write("국어점수를 입력하세요 : ");
               iP.korScore = int.Parse(Console.ReadLine());
               Console.Write("영어점수를 입력하세요 : ");
               iP.engScore = int.Parse(Console.ReadLine());
               Console.Write("수학점수를 입력하세요. : ");
               iP.mathScore = int.Parse(Console.ReadLine());
               iP.sE = (iP.korScore + iP.engScore + iP.mathScore) / 3;
               iData.Add(iP);
               korS += iP.korScore;
               engS += iP.engScore;
               mathS += iP.mathScore;
           }
           Console.WriteLine("{0,3} | {1,-3} | {2,-3} | {3,-3} | {4,-3}", "이  름", "국어", "영어", "수학", "평균");
           foreach(InputData aa in iData)
           {
               Console.WriteLine("{0,3} | {1,-5} | {2,-5} | {3,-5} | {4,-5}", aa.name, aa.korScore, aa.engScore, aa.mathScore, aa.sE);
           }
           Console.WriteLine("{0,3} | {1,-5} | {2,-5} | {3,-5} | {4,-5}", "평  균", korS / 3, engS / 3, mathS / 3, "");
       }
  }
}


출력화면

사용자 삽입 이미지

이 숙제는 선생님이 몇 일전에 내 줬었다.
하지만 그땐 잘 이해를 못했는데 몇일 지나고 나니 해결되었다.

아직 struct와 배열부분은 확실히 이해가 된게 아니라 ...걱정된다.
큰일이다.
빨리 이해가 되어야할텐데 ...

TRACKBACK URL : 이 글에는 트랙백을 보낼 수 없습니다