#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
double add(double operand1, double operand2) { return operand1 + operand2; }
double subtract(double operand1, double operand2) { return operand1 - operand2; }
double multiply(double operand1, double operand2) { return operand1 * operand2; }
double divide(double operand1, double operand2) { return operand1 / operand2; }
typedef double(*OPERATOR)(double, double);
OPERATOR operators[4] = {add, subtract, multiply, divide};
int main()
{
char input_string[256];
const char opcodes[] = "+-*/";
cout << "usage : operand1 opcode operand2 (ex: 3*8 or 3 * 8)" << endl;
cin.getline(input_string, sizeof(input_string));
char* ptr = input_string;
while(*ptr && !strchr(opcodes, *ptr)) ptr++;
int opcode = int(strchr(opcodes, *ptr) - opcodes);
double operand1 = atof(strtok(input_string, opcodes));
double operand2 = atof(strtok(NULL, " "));
cout << operand1 << " " << opcodes[opcode] << " " << operand2 << " = "
<< operators[opcode](operand1, operand2) << endl;
getchar();
return 0;
}
님들 저 소질 있나요? 뿌잉뿌잉.
역폴리쉬 표현방식으로 수식표현해서 수식트리구성해서 후위순회로구현해야지
/ 0 하면....
@수크라제 그런건 너무어려워서 20년 전에 다 해봤다니께요 ㅠ_ㅠ 초보 무시하시네
@우물개구리 0으로 나누면 안된다는걸 제대로 출력하게 설계되어있어용
x+y가 안돼서 탈락
@ㅅㅅㅅ 무료버전에선 x,y가 각각 0인 경우만 지원해용. 유료 결제하시면 자동 업데이트 돼용
데모버전이었군용
@ㅅㅅㅅ 넹 아직 if 나 switch 까지 안들어간 늅늅이 코드니까 이해해주세용
http://dblack.tk
커뮤니티 사이트 입니다 많은 이용 부탁 드립니다.