#include <iostream>
int main() {
int x,y,z,w;
double a,s,d;
x = 0;
z = 0;
y = 0;
d = 0;
s = 0;
a = 0;
std:: cout <<"1 for addition 2 for subtraction 3 for multiplication and 4 for division" << std::endl;
std:: cin >>z;
if(z==1)
{
std:: cout <<"enter first number" << std::endl;
std:: cin>>x;
std:: cout <<"enter second number" << std::endl;
std:: cin>>y;
w= x+y;
std:: cout<<w;
}
if(z==2)
{
std:: cout <<"enter first number" << std::endl;
std:: cin>>x;
std:: cout <<"enter second number" << std::endl;
std:: cin>>y;
w= x-y;
std:: cout<<w;
}
if(z==3)
{
std:: cout <<"enter first number" << std::endl;
std:: cin>>x;
std:: cout <<"enter second number" << std::endl;
std:: cin>>y;
w= x*y;
std:: cout<<w;
}
if(z==4)
{
std::cout << "enter first number"<< std::endl;
std::cin >>a;
std::cout <<"enter second number"<< std::endl;
std::cin>>s;
d=z/s;
std::cout<<"the ans is " << d;
}
return 0;
}
this is the code for a calculator and acording to it 2/2 = 2 and 3/3 = 1.333 but when i try to do these sepratly in seprate codes it shows correct answer
i was expectiing it to work i took a lot of time trying to find the problem to no avail
New contributor
Shreeansh 2 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.