【发布时间】:2014-12-21 20:15:15
【问题描述】:
如何使用数字参数创建操作方法(int op),以便我可以通过操作(1)或操作(3)调用其他方法?我想我需要创建一个开关,但我不确定如何。
int subtraction(int n1, int n2) { //e.g. of simple method
return n1 - n2;
}
int multiplication (int n1, int n2){
return n1*n2;
}
int operation(int op) {
// code that will call the method subtraction when I press 1.
// same for multiplication...
}
int main () {
}
【问题讨论】:
-
您是在问如何使用
if语句吗? -
为什么不参加讲座并学习这些东西?
-
我想他是在问如何使用
switch声明。
标签: c++ methods switch-statement