Actually this is a code of basic calculator and it is passing all the test cases but when i am trying this with some random input it giving wrong output. Can you please point out my mistake
Basic calulator
#include using namespace std; int main() { while(1) { char ch; cin>>ch; if(ch==β+β||ch==β-β||ch==ββ||ch==β/β||ch==β%β) { long long int n1,n2,n3; cin>>n1>>n2; if(ch==β+β) n3=n1+n2; else if(ch==β-β) n3=n1-n2; else if(ch==ββ) n3 = n1*n2; else if(ch==β/β) { if(n2==0) break; else n3 = n1/n2; } else if(ch==β%β) { if(n2==0) break; else n3 = n1%n2; } cout<<n3<<endl; } else if(ch==βXβ||ch==βxβ) break; else { cout<<βInvalid operation. Try again.β<<endl; continue; } } return 0; }
9/3,2*2,8-3 these are some inputs
9/3,6*2,8-2 these are some inputs that i am giving
9/3,6*2,8-2 these are some inputs that i am giving bug
hi @agarwaldaksh360_2bae042448e62c08 buddy u r giving wrong input
first give operator than operande
eg --> / 9 3 X
oh ok but can there be another code where it is not necessary
@agarwaldaksh360_2bae042448e62c08,
rn proceed with the course you will learn everything dont worry, read about strings and arrays then u can try
why rhere is 1 in the bracket of while loop
I hope Iβve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.