Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

CSC112 Spring 2016 Examples

2369 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 "Problem!";
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
}
26
27
cout << "The odd version of your number is: " << x << endl;
28
29
return 0;
30
}
31