summaryrefslogtreecommitdiff
path: root/5p25.cpp
blob: 6a3fbf631b0998b4c771b4779ad25812034c2ac3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <stdexcept>

/*
 *
 * 5.23
 *
 *
 */

int main () {

	int a = 0;
	int b = 0;
	bool d = true;
	while(d) {
		d = false;
		try {
			std::cin >> a >> b;
			if(b == 0) {
				throw std::runtime_error("divide by 0!");
			}

			std::cout << a / b << std::endl;			
		} catch(std::runtime_error &err) {
			std::cout << err.what() << "\nTry again? Y/N " << std::endl;
			char c = 0;
			std::cin >> c;
			if(c == 'Y' || c == 'y') {
				d = true;
			}
		}

	}
	
	return 0;
}