如何将程序从主发送到另一种方法
How can I send the program from main to another method?
我想打印cout
的输出,但是代码不起作用。任何提示都会有所帮助。
int main()
{
cout<<"10+20"<<calc(10,20,+);
cout<<"10*20"<<calc(10,20,*);
cout<<"10-20"<<calc(10,20,-);
cout<<"10/20"<<calc(10,20,/);
}
int calc (int a, int b, char c)
{
int total=0;
if(c=='+'){
total = a+b;
}else if(c=='*'){
total = a*b;
}else if(c=='-'){
total = a-b;
}else if(c=='/'){
total = a/b;
}
return total;
}
当您以字符参数传递时,操作员必须将其包含在单引号中。
int main()
{
cout<<"10+20"<<calc(10,20,'+');
cout<<"10*20"<<calc(10,20,'*');
cout<<"10-20"<<calc(10,20,'-');
cout<<"10/20"<<calc(10,20,'/');
}
相关文章:
- 只需要知道我在c ++中打印模式的方式是否有效,或者有另一种方法可以有效地做到这一点
- 如何在一种方法中创建对象并在另一种方法中使用它
- 常量静态成员函数:有另一种方法可用吗?
- 如何将程序从主发送到另一种方法
- 如何使用shared_ptr或推荐另一种方法(unique_ptr)
- 在C++编程中继续下一行的另一种方法是什么?
- 是否有另一种方法可以在不使用宏定义的情况下进行此操作
- 将带有参数的void方法传递给使用std ::函数和std :: bind c 的另一种方法
- C++:访问由另一种方法返回的向量的常量向量时出现分段错误
- 一个人如何将腋窝VEC/MAT作为REF论点传递给另一种方法
- Visual Studio 2003使用regex的另一种方法
- C++另一种方法计算平均值
- 在cuda中使用静态成员函数模板结构的另一种方法
- C++-使用循环的另一种方法
- 在C++03中初始化成员的另一种方法
- 获取十六进制字符串的字节长度的另一种方法
- 如何让一些派生类使用相同的方法,而另一些派生类则使用另一种方法
- 除以2的另一种方法是什么?
- 是否有另一种方法调用基方法从派生是虚拟的
- 在数据结构中保存成员的另一种方法