List of all available Websheets
Viewing cpp/cs104/exceptions/divide1 by redekopp@usc.edu. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
Property | Value |
---|---|
Description html markup shown to student | In the example below a divide-by-0 will cause the program to crash if the user enters the value of <tt>2</tt> <p> <p> In subsequent exercises we will see how to fix this problem. |
Engine | |
Template / Reference solution |
using namespace std; int divide(int num, int denom) { if(denom == 0) { cout << "Denom is 0" << endl; } return(num/denom); } int f1(int x) { return divide(x, x-2); } int main() { int res = -1, a; cout << "Enter: " << endl; cin >> a; res = f1(a); cout << res << endl; return 0; } |
C++ test suite json list of stdin/args tests e.g. [{"stdin":"hi", "args":["4", "5"]}, {"stdin":"noargs"}] to just run once with no input use [{}] | [{"stdin":"2"}] |
Is example? i.e., just a demo |
Note: problems are open-source by default (see 'Public permissions'). Assumed license for open problems is Creative Commons 4.0 Attribution-ShareAlike unless specified in 'Remarks'.