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; }
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;
}
0
Nope, it has to be
int a;
int b;
char c;