Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

CSC112 Spring 2016 Examples

2370 views
1
#include <iostream>
2
3
using namespace std;
4
5
int oddify(int x) {
6
if(x%2 == 0) {
7
return x-1;
8
}
9
10
throw 7;
11
}
12
13
int main()
14
{
15
int x;
16
17
cout << "Enter an integer: ";
18
cin >> x;
19
20
try {
21
x=oddify(x);
22
} catch(const char *ex) {
23
cerr << "An exception happened: " << ex << endl;
24
return -1;
25
} catch(int ex) {
26
cerr << "Integer Error Occured: " << ex << endl;
27
return -2;
28
}
29
30
cout << "The odd version of your number is: " << x << endl;
31
32
return 0;
33
}
34