I am new to C++ and am looking to expand my knowledge. Below is a simple program that I've made. I would like to know how it could be improved, in any way. The introduction of new ways to do things is what I am looking for. These could be anything from improving efficiency to validating input - just whatever you think is most important or beneficial.
float calculate(float x, char y, float z) {
float answer;
switch (y) {
case '+':
answer = x + z;
break;
case '-':
answer = x - z;
break;
case '/':
answer = x / z;
break;
case '*':
answer = x * z;
break;
default:
return(0);
}
cout <<"= "; return answer;
}
int main() {
float num1;
float num2;
char aOp;
cout << ">> ";
cin >> num1 >> aOp >> num2;
cout << calculate(num1, aOp, num2) << endl << endl;
}