hi
i have made a calculator code with if statement.
but i dont know why it doesnt work correctly.
it attentions on the first if task without including the condition.
so it only plus the first num to second num!
wether you put +,-,/,* it only add them to each other!
if (b = '+')
this is an assignment. It says, assign b to the plus character, and then evaluate to TRUE (because the + symbol is not zero, it is true, if this had been '\0' it would still be wrong and FALSE).
you want
if (b == '+')
which says "if b is the plus symbol, true, otherwise false"
the while condition may also bug out. If it overflows the wrong way, which I didnt investigate, it could actually fail in a strange way. Just make it -999. B is a char, it can't be more than +- 128, so -999 is more than sufficient. However -999 is also a bit off, just do while(true) to loop forever. There is no good reason to put a complex condition that can't fail in.
a simplistic way to do that is
while (b!= '/' ||(b=='/'&& x%y != 0))
you can't repeat without a loop of some sort or a goto (gotos are generally bad programming).
you can interchange all loops (with some effort at times) but do-while seems right here.