티스토리 뷰
문제 : 두 자연수를 입력으로 받아 사각형의 넓이를 구하는 프로그램을 작성하시오.
제한 조건 :
두 자연수 가 입력으로 주어지고 , 각각 가로 , 세로 길이이다.단위는 같은 것으로 가정
두 수는 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
- 덤프
- 인천
- PPTX
- jdk
- 가평여행
- 테라로사
- 제주도여행
- 오라클
- 정동지
- ora-01940
- 담양 죽녹원
- 부천역
- 산외한우마을
- 밀리세컨드
- 파주여행
- 임자도
- 인스타그램
- 토드
- 인천여행
- 보성녹차밭
- oracle
- java api
- 맛집
- 대관령양떼목장
- 가평팬션
- pdf ms워드 변환
- 이클립스
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |