728x90
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
 
//이름/국영수 점수 입력받고 이름/국영수점수/총점/평균/석차 출력
 
namespace SScore
{
    class Student
    {
        public string Name;
        public int Kor;
        public int Eng;
        public int Math;
 
        public int input(object[] arr, int Cnt)
        {
            //이곳에 이름, 국영수 점수 입력받고 총점과 평균을 구한다  
            Console.Write("이름 입력 : ");
            Name = Console.ReadLine();
 
            while (true)
            {
                Console.Write("첫번째 점수 : ");
                Kor = int.Parse(Console.ReadLine());
                if (Kor < 0 || Kor > 100)
                    continue//반복문을 리셋하세요(반복문의 처음 위치로 이동)
 
                ReInput://Label statement
                Console.Write("두번째 점수 : ");
                Eng = int.Parse(Console.ReadLine());
                if (Eng < 0 || Eng > 100)
                    goto ReInput;//지정된 label statement로 이동
                do
                {
                    Console.Write("세번째 점수 : ");
                    Math = int.Parse(Console.ReadLine());
                } while (Math < 0 || Math > 100);
 
                int Sum = Kor + Eng + Math;
                Double Avg = Sum / 3;
 
                arr[Cnt] = Name + "\t" + Kor + "\t" + Eng + "\t" + Math + "\t" + Sum + "\t" + Avg + "\t";
 
                return Sum;
            }
        }
 
        class Program
        {
            static void Exception(int arg)
            {
                if (arg < 2)
                    Console.WriteLine("arg : {0}", arg);
                else
                    throw new Exception("arg가 10보다 큽니다.");
            }
 
            static void Main(string[] args)
            {
                object[] arr = new object[20];
                int[] arr_sum = new int[20];
                int[] rank = new int[20];
 
                Student std = new Student();
 
                char select;
                int Cnt = 0;
 
                while (true)
                {
                    Console.WriteLine("=====================================학생 성적 관리 프로그램=====================================");
                    Console.WriteLine("1. 학생성적 입력 ");
                    Console.WriteLine("2. 학생성적 보기 ");
                    Console.WriteLine("Q. 프로그램 종료 ");
                    Console.WriteLine("=================================================================================================");
 
                    Console.Write(" 메뉴선택 ( 1,2 또는 Q 입력 ) : ");
                    try
                    {
                        select = char.Parse(Console.ReadLine());
 
                        if (select == '1')
                        {
                            arr_sum[Cnt] = std.input(arr, Cnt);
                            Cnt++;
                        }
                        else if (select == '2')
                        {
                            Console.WriteLine();
                            Console.WriteLine("==============종합결과===============");
                            Console.WriteLine("성명\t국어\t영어\t수학\t총점\t평균\t순위");
 
                            for (int i = 0; i < Cnt; i++)
                            {
                                rank[i] = 1;
                                for (int a = 0; a < Cnt; a++)
                                {
                                    if (arr_sum[i] < arr_sum[a])
                                    {
                                        rank[i]++;
                                    }
                                }
                                Console.WriteLine("{0}{1}", arr[i], rank[i]);
                            }
                            break;
                        }
                        else if (select == 'q')
                        {
                            Console.Write("프로그램이 종료됩니다.");
                            break;
                        }
                        else if (select == 'Q')
                        {
                            Console.Write("프로그램이 종료됩니다.");
                            break;
                        }
                    }
 
                    catch (Exception e)
                    {
                        Console.WriteLine("올바른 값을 입력하세요");
                    }
                }
            }
        }
    }
}


'Study > C#' 카테고리의 다른 글

c# 복습  (0) 2017.03.31
headfirst c#-wpf  (0) 2016.11.19
c# 클래스 복습2  (0) 2016.05.23
c# 스터디일지 -클래스  (0) 2016.05.22
2016-05-20-C#복습  (0) 2016.05.20

+ Recent posts