- 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; }
8 Respuestas
+ 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;
}
+ 2
You can also look at hints or reveal the answer in a quiz.
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;
}
0
try {
int a; int b;
cin >> a >> b;
if (b == 0)
throw 0;
cout << a / b << endl;
} catch (int err) {
cout << "error" << endl;
}
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;
}
}
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
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;
}
- 3
#include <iostream>
#include < >
int main() {
ofstream fileObj("myfile.txt");
(fileObj. ()) {
fileObj << "I work with files";
fileObj.close();
} else {
cout << "Error" << endl;
}
}