From 4e1a36a8eb83f9d33f5ac1aebeebafe5ac89e511 Mon Sep 17 00:00:00 2001 From: Yue Wang Date: Mon, 22 Jun 2015 02:54:45 +1200 Subject: [PATCH] Update ex5_24.cpp --- ch05/ex5_24.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/ch05/ex5_24.cpp b/ch05/ex5_24.cpp index f6743098..a1ce76e8 100644 --- a/ch05/ex5_24.cpp +++ b/ch05/ex5_24.cpp @@ -1,17 +1,20 @@ #include #include -using namespace std; +// +// When a zero entered, the code below would crash with feedback as : +// "Unhandled exception at 0x75834598 in just_for_cpp.exe: Microsoft C++ exception: std::runtime_error at memory location 0x0054F9F4." +// +// Tested on Windows 8.1 + Vs 2013 +// int main(void) { - int a, b; - cin >> a >> b; + int i, j; + std::cin >> i >> j; + if (j == 0) + throw std::runtime_error("divisor is 0"); + std::cout << i / j << std::endl; - if (b == 0) - throw runtime_error("divisor is 0"); - - cout << static_cast(a) / b << endl; - - return 0; + return 0; }