- 1

Which is the answer?

Drag and drop from the options below to enter two integers and print their division to the screen. Use try and catch blocks to handle division by 0. ___{ int a; int b; cin >> a >> b; if (b == 0) ___ 0; cout << a / b << endl; }____ (int err) { cout << "error" << endl; }

28th Nov 2018, 12:27 AM
cristian jerez figueroa
cristian jerez figueroa - avatar
8 Answers
+ 9
#include <iostream> using namespace std; int main() { try{ int a; int b; cin >> a >> b; if (b == 0) throw 0; cout << a / b << endl; }catch (int err) { cout << "error" << endl; } return 0; }
28th Nov 2018, 6:57 AM
Rstar
Rstar - avatar
+ 2
You can also look at hints or reveal the answer in a quiz.
28th Nov 2018, 8:36 AM
Matthias
Matthias - avatar
0
try{ int a; int b; cin >> a >> b; if (b == 0) throw 0; cout << a / b << endl; }catch (int err) { cout << "error" << endl; } return 0; }
24th Apr 2019, 6:39 AM
Farshid Rahimi
Farshid Rahimi - avatar
0
try { int a; int b; cin >> a >> b; if (b == 0) throw 0; cout << a / b << endl; } catch (int err) { cout << "error" << endl; }
27th Sep 2019, 6:26 PM
Shaima Alassil
Shaima Alassil - avatar
0
#include <iostream> #include <fstream> int main() { ofstream fileObj("myfile.txt"); if (fileObj.is_open()) { fileObj << "I work with files"; fileObj.close(); } else { cout << "Error" << endl; } }
26th Apr 2020, 6:42 PM
V.SATHYA
V.SATHYA - avatar
0
drag and drop from the options below to enter to enter two integers and print their division to the screen. use try and catch blocks to handle division by 0. ANSWER:- TRY THROW CATCH
24th May 2020, 2:05 PM
Shailesh Kumar meena
Shailesh Kumar meena - avatar
0
Drag and drop from the options below to enter two integers and print their division to the screen. Use try and catch blocks to handle division by 0. Answer: try { int a; int b; cin >> a >> b; if (b == 0) throw 0; cout << a / b << endl; } catch (int err) { cout << "error" << endl; }
23rd Sep 2020, 12:39 AM
OjeifoIduma
- 3
#include <iostream> #include < > int main() { ofstream fileObj("myfile.txt"); (fileObj. ()) { fileObj << "I work with files"; fileObj.close(); } else { cout << "Error" << endl; } }
13th Dec 2019, 2:27 PM
fatma