0

What’s wrong specifically in { in line 21 ?

https://sololearn.com/compiler-playground/c60552CH3pcA/?ref=app

28th Dec 2023, 10:15 PM
Basma
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
29th Dec 2023, 1:59 AM
Bob_Li
Bob_Li - avatar
+ 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.
29th Dec 2023, 2:08 AM
Bob_Li
Bob_Li - avatar
+ 1
Bob_Li switch condition dosen’t work , he just executed default without other operations
29th Dec 2023, 7:48 AM
Basma
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
29th Dec 2023, 8:13 AM
Bob_Li
Bob_Li - avatar
0
Bob_Li Okk , thanks
29th Dec 2023, 5:22 PM
Basma