0

Why all if statements go true ?

//simple calculator #include <iostream> using namespace std; int main() {int i,a;float s=0; char op,o; cout<<"Enter the number of operations :"; cin>>i;//where i is the number of operations cal :cout<<"Enter the number(a) :"; cin>>a; cout<<"Enter +, -, × or ÷ : "; cin>>op;//where op is the sign of operator o=op; if (op ='+') cout<<"+"<<endl; if (o ='÷') cout<<"÷"<<endl; if (op ='-') cout<<"-"<<endl; if (op ='×') cout<<"×"<<endl; i=i-1; if (i != 0) goto cal; cout<<"The result is "<<s; return 0; } Inputs : 1 1 - Output: + ÷ - × The result is 0

2nd Jan 2021, 9:32 PM
حازم الباز
حازم الباز - avatar
2 Respostas
+ 7
You should use "==" operator Instead of "="
2nd Jan 2021, 9:38 PM
Marina Vasilyova
Marina Vasilyova - avatar
+ 1
You should use a comparison operator "Equal to"(==) Best of Luck! //simple calculator #include <iostream> using namespace std; int main() { float i=0, a=0; float s=0; char op; cout<<"Enter the 1st number : ";// number 1(i) cin>>i; cal :cout<<"Enter the 2nd number : ";// number 2(a) cin>>a; cout<<" Addition(+) \n Subtraction(-) \n Division(/) \n Multiplication(*) \n"; cout<<"Enter what do you want : "; cin>>op;//where op is the sign of operator if (op =='+'){ s=i+a; cout<<s<<endl; } if (op =='/'){ s=i/a; cout<<s<<endl; } if (op =='-'){ s=i-a; cout<<s<<endl; } if (op =='*'){ s=i*a; cout<<s<<endl; } return 0; }
3rd Jan 2021, 12:25 AM
Poorna Wijesinghe
Poorna Wijesinghe - avatar