0

function error

hello guys i'm trying to resolve this, for a while but i couldn't please healp here's my source code: #include <iostream> using namespace std; float fonction (float x , float y , char n); { ---------------------// error "Expected unqualified-id" float sum; switch ('n') { case '+' : sum =x+y; cout<<" le resultat de :"<<x<<"+"<<y<<" = "<<sum << endl; break; case '-' : sum =x-y; cout<<" le resultat de :"<<x<<"-"<<y<<" = "<<sum<< endl; break; case '*' : sum =x*y; cout<<" le resultat de :"<<x<<"*"<<y<<" = "<<sum<< endl; break; case '/' : sum =x/y; cout<<" le resultat de :"<<x<<"/"<<y<<" = "<<sum<< endl; break; default '+': sum =x+y; } return sum; } int main(int argc, const char * argv[]) { // insert code here... float a=12; float b=17; float fonction (float a ,float b, char (n)) ; return 0; }

3rd Mar 2019, 5:29 PM
Akagami
Akagami - avatar
3 odpowiedzi
+ 2
Akagami 👌☺️
3rd Mar 2019, 6:35 PM
Anna
Anna - avatar
+ 4
switch('n') => switch(n) Remove the semicolon in line 4 default '+' isn't possible. Either default: or case '+': float fonction (float a ,float b, char (n)) in main() is another function declaration, not a function call. You don't call the function anywhere. It is called like this: fonction(a, b, c)
3rd Mar 2019, 6:01 PM
Anna
Anna - avatar
+ 1
thank's a lot its much better like this : #include <iostream> using namespace std; float fonction (float x , float y , char n) { float sum; switch (n) { case '+' : sum =x+y; break; case '-' : sum =x-y; break; case '*' : sum =x*y; break; case '/' : sum =x/y; break; default: sum =x+y; } return sum; } int main(int argc, const char * argv[]) { // insert code here... float fonction (float, float, char); float a,b; char n ; cout<< "insert the values"<<endl; cin>> a>>b; cin>> n ; cout<<" le resultat de :"<<a<<"+"<<b<<" = "<<fonction(a, b, '+')<< endl; cout<<" le resultat de :"<<a<<"-"<<b<<" = "<<fonction(a, b, '-')<< endl; cout<<" le resultat de :"<<a<<"*"<<b<<" = "<<fonction(a, b, '*')<< endl; cout<<" le resultat de :"<<a<<"/"<<b<<" = "<<fonction(a, b, '/')<< endl; return 0; }
3rd Mar 2019, 6:31 PM
Akagami
Akagami - avatar