what is the wrong wih my code? [closed]
#include <iostream>
using namespace std;
float sum(float a,float b);
float subs(float a, float b);
float multiple(float a, float b);
float division(float a, float b);
int main()
{//main
int a,b;
char o ;
cout<<"input your calculation with operation (+,-,/,*) such as 5+6 : /n ";
cin >> a >> o >> b ;
switch('o')
{
case '+':
sum(float a, float b);
break;
case '-':
subs(float a, float b);
break;
case '*':
multiple(float a, float b);
break;
case '/':
division(float a, float b);
break;
default :
cout << "error, try again " <<endl;
}
return 0;
}//main
float sum(float a,float b)
{//sum
float total= a+b;
return total;
}//sum
float subs(float a, float b)
{//subs
float total=a-b;
return total;
}//subs
float multiple(float a, float b)
{//multiple
float total=a*b;
return total;
}//multiple
float division(float a, float b)
{//division
float total=a/b;
Superficially, you're missing a curly bracket at the end. Operationally, your switch statement is switching on a constant, 'o', instead of the variable o.
Change:
switch('o')
to
switch(o)
精彩评论