using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("정수 사칙연산 계산기입니다.");
while (true)
{
Console.Write("첫번째 숫자를 입력하세요 : ");
int input1 = Convert.ToInt32(Console.ReadLine());
Console.Write("연산기호를 입력하세요(+,-,*,/) : ");
string input2 = Convert.ToString(Console.ReadLine());
Console.Write("두번째 숫자를 입력하세요 : ");
int input3 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("결과 : {0}", Calculator(input1, input2, input3));
}
}
static string Calculator(int a, string sign, int b)
{
if (sign == "+")
{
return Convert.ToString(a + b);
}
else if (sign == "-")
{
return Convert.ToString(a - b);
}
else if (sign == "*")
{
return Convert.ToString(a * b);
}
else if (sign == "/")
{
Console.WriteLine("나머지 : {0}", a % b);
return Convert.ToString(a / b);
}
else
{
return "잘못 입력하셨습니다.";
}
}
}
}
'C# > 수업 내용' 카테고리의 다른 글
클래스 생성, 인스턴스 생성 연습 (저그) (0) | 2021.12.23 |
---|---|
클래스 만들기-생성자 메서드 (라바-드론 생산) (0) | 2021.12.23 |
반환값이 있는 메서드 연습 (벌쳐, 템플러, 홀짝 판단, 줄넘기) (0) | 2021.12.23 |
메서드와 지역변수, 전역변수 복습 (0) | 2021.12.23 |
반환값은 없고 매개변수가 있는 메서드 연습 (0) | 2021.12.23 |