이거 답변 좀 주시면 안될까요?
2014-10-14
|
by lecture114
1275
// 안녕하세요 글쓴이 : 책 질문 SQL-SERVER-2012 도 질문한 사람입니다.
// 아래 내용은 길벗 출판사 예전 책 내용인데 답변을 안줘서 ... 답변 좀 부탁드려도 될까요?
// 한빛미디어 출판사 홈페이지에서도 답변이 없습니다 ...
#include
using namespace std;
#define PLUS(a, b) (a + b);
#define MINUS(a, b) (a - b);
#define MULTIPLE(a, b) (a * b);
#define DIVIDE(a, b) (a / b);
void main()
{
float input1, input2;
char operator_variable;
float result;
cout << "입력 = ";
cin >> input1 >> operator_variable >> input2;
switch(operator_variable)
{
case + :
result = PLUS(input1, input2);
cout << input1 << " " << operator_variable << " " << input2 << " = " << result << endl;
break;
case - :
result = MINUS(input1, input2);
cout << input1 << " " << operator_variable << " " << input2 << " = " << result << endl;
break;
case * :
result = MULTIPLE(input1, input2);
cout << input1 << " " << operator_variable << " " << input2 << " = " << result << endl;
break;
case / :
result = DIVIDE(input1, input2);
cout << input1 << " " << operator_variable << " " << input2 << " = " << result << endl;
break;
default :
cout << "잘못된 연산자를 입력했습니다." << endl;
cout << "프로그램을 종료합니다." << endl;
break;
}
}
// 실행 결과
10 / 3 = 3.33333
소수점 5자리까지 출력되는 이유 좀 알려주세요 ...