티스토리 뷰

개발/산출물(C#)

사각형의 넓이

개발자와코더사이가 PM일까? 2011. 4. 21. 01:12
반응형


문제 : 두 자연수를 입력으로 받아 사각형의 넓이를 구하는 프로그램을 작성하시오.
제한 조건 :
두 자연수 가 입력으로 주어지고 , 각각 가로 , 세로 길이이다.단위는 같은 것으로 가정
두 수는 1000 을 넘지 않는다.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AREA
{
    public struct Line
    {
        public int intWidth;
        public int intHeight;
        public int intArea;
    }

    public class Program
    {
 
        public static void Main(string[] args)
        {
            Line line = InFunction();

            if (CheckFunction(line.intHeight, line.intWidth))
            {
                line.intArea = CalcArea(line.intHeight, line.intWidth);
                Print(line.intArea);
            }
            else
            {
                System.Console.WriteLine("두수의 합이 1000이 넘었습니다.");
            }
        }

        //1.입력함수-자연수만 받아야 한다.
        private static Line InFunction()
        {
            Line line = new Line();
         
            bool result1 = true;
            bool result2 = true;
           
            Width:   
            System.Console.WriteLine("넓이를 입력하세요");
            result1 = Int32.TryParse(System.Console.ReadLine(), out line.intWidth);

            if(!result1)
              goto Width;

            Height:
            System.Console.WriteLine("높이를 입력하세요");
            result2 = Int32.TryParse(System.Console.ReadLine(), out line.intHeight);

            if (!result2)
                goto Height;
           
            return line;
        }

        //2.입력 제한 체크 함수
        //두수는 1000를 넘지 않는다.
        private static bool CheckFunction(int Variable1, int Variable2)
        {
            bool checkvalue = true; //반환값 변수
            int intVar1 = Variable1;
            int intVar2 = Variable2;

            if (intVar1 + intVar2 > 1000)
                checkvalue = false;
            else
                checkvalue = true;

            return checkvalue;
        }

        //3.계산식
        //가로 * 세로 = 넓이
        private static int CalcArea(int Variable1, int Variable2)
        {
            int intResult = 0;
            int intVar1 = Variable1;
            int intVar2 = Variable2;

            intResult = intVar1 * intVar2;

            return intResult;
        }

        //4.출력
        private static void Print(int value)
        {
            System.Console.WriteLine("사각형넓이는:");
            System.Console.WriteLine("{0}", value);
            System.Console.Read();
        }
    }
  
}

 

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함