+ 1

Problem with my calculator again....

I noticed that if you try to devide 0 by 0 the program crashes so I wrote if (num1 && num2 == 0) { cout << "You can't devide zero by zero"; } else { cout << num1 << " devided by " << num2 << " equals " << num1 / num 2; But it still crashes if I set num1 and num2 to zero. Any help?

31st Jul 2018, 4:15 PM
Elias Kamakas
Elias Kamakas - avatar
1 Answer
+ 5
You forgot to check if num1 == 0. Edit: Elias Kamakas , since you divide by num2 only, then you need just: if (!num2) { // If num2 is 0 cout << "Division by zero"; }
31st Jul 2018, 4:32 PM
Boris Batinkov
Boris Batinkov - avatar