0
Whatâs wrong specifically in { in line 21 ?
https://sololearn.com/compiler-playground/c60552CH3pcA/?ref=app
5 Answers
+ 1
/*Sololearn sample input
1 2 +
submit
*/
#include <iostream>
using namespace std;
void operation(char, float, float);
int main(){
float num1 ,num2 ;
char op;
cout<<"Enter two number : "<<endl;
cin>>num1>>num2;
cout<<"Choose the operation( + , - ,* , / ):" <<endl;
cin>>op;
operation(op, num1, num2);
}//close main
void operation(char op, float n1, float n2){
switch(op){
case '+':
cout<<n1<<" + "<<n2<<" = "
<<n1+n2<<endl; break;
case '-':
cout<<n1<<" - "<<n2<<" = "
<<n1-n2<<endl; break;
case '*':
cout<<n1<<" * "<<n2<<" = "
<<n1*n2<<endl; break;
case '/':
if(n2==0)
cout<<"Division by zero is not allowed."<<endl;
else
cout<<n1<<" / "<<n2<<" = "
<<n1/n2<<endl; break;
default:
cout<<"your input is invalid"<<endl;
break;
} //close switch
}//close fun op
+ 1
Basma
Define your function outside main(){}.
Also, your function have an error. You are supposed to pass the argument to the switch, not the function name...
switch(op)
not
switch(operation)
And the return value should be void, not char, since you are only doing cout.
+ 1
Bob_Li switch condition dosenât work , he just executed default without other operations
0
Basma
put a blank space between the inputs in Sololearn
12 25 +
submit
or put them in separate lines
12
25
+
submit
also, look at my comment under your code if you want the input to be something like:
12 + 25
submit
or
12
+
25
submit
0
Bob_Li Okk , thanks