Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

CSC112 Spring 2016 Examples

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