Question to sololearn | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Question to sololearn

Is this code right: #include <iostream>; using namespace std; main sring() { int a; int b; int c; cin>>a; cin>>b; cin>>c; /*First enter the first number then enter the second number and finally enter the sign to indicate the operation*/ if (c==-); cout<<a-b<<endl; if (c==+) cout<<a+b<<endl; if (c==/) cout<<a/b<<endl; if (c==*) cout<<a*b<<endl; if (c==%) cout<<a%b<<endl; else cout<<"somethings wrong""<<endl; }

26th Aug 2017, 3:35 PM
Surendra Rajawat
Surendra Rajawat - avatar
2 Answers
+ 7
#include <iostream> using namespace std; int main() { int a, b; char c; cin>>a; cin>>b; cin>>c; /*First enter the first number then enter the second number and finally enter the sign to indicate the operation*/ if (c=='-'); cout<<a-b<<endl; if (c=='+') cout<<a+b<<endl; if (c=='/') cout<<a/b<<endl; if (c=='*') cout<<a*b<<endl; if (c=='%') cout<<a%b<<endl; else cout<<"somethings wrong""<<endl; return 0; }
26th Aug 2017, 3:57 PM
Hatsy Rei
Hatsy Rei - avatar
0
Nope, it has to be int a; int b; char c;
26th Aug 2017, 3:58 PM
ReimarPB
ReimarPB - avatar