Help With Calculator

I made a calculator that allows you to do different operation based off of what number you type in for the first one, but its only doing addition, an someone help me.

[code]

int main()
{
std::string name;
int x;
int y;
int z;
std::cout << "What is your name? ";
getline (std::cin, name);
std::cout << "Thanks for using my calculator " << name << "!";
std::cout << " What's the operation? ";
std::cin >> z;
std::cout << " What's the first number? ";
std::cin >> y;
std::cout << "What's the second number? ";
std::cin >> x;
if (z = 1){
std::cout << x << " + " << y << " = ";
std::cout << x + y;
}else if (z = 3){
std::cout << x << " x " << y << " = ";
std::cout << x * y;
}else if (z = 2){
std::cout << x << " - " << y << " = ";
std::cout << x - y;
}else if (z = 4){
std::cout << x / y;
std::cout << x << " / " << y << " = ";
}else
std::cout << "Sorry, this calculator does not understand that operation, please pick a number 1 to 4";
}

if (z = 1)

should be if (z == 1)

Ha, classic error!
Thanks
Everyone who does this assignment forgets to check for divide by zero . And initialize their variables. And use code tags.

www.cplusplus.com/articles/z13hAqkS/
Topic archived. No new replies allowed.