#include
#include
using namespace std;
/*
* The program checks if a number is "extremely" odd.
*
* A number n is extremely odd if all of the following are true:
*
* (0) n is odd
* (1) all digits of n are odd
* (2) n has an odd number of digits
*
* @creator gdt
* @created 02018.10.15
* @edu written during a csc100 class to help learn
* about the 'break' and 'continue' statements
*/
int main(int, char**) {
const int EXIT = 0;
int n;
do {
cout << "enter a positive int (" << EXIT << " to stop): ";
cin >> n;
if (cin.fail()) {
cout << "*** error: an integer was not entered\n";
break;
}
if (n == EXIT) {
cout << "okay -- we're done\n";
break;
}
if (n % 2 == 0) {
cout << n << " is even; only odd numbers can be extremely odd\n";
continue;
}
if (n < 0) {
cout << n << " is not a positive number\n";
continue;
}
int x = n;
int count = 0;
while (x != 0) {
int d = x % 10;
count++;
if (d % 2 == 0) {
break;
}
x = x / 10;
}
if (x != 0 || count % 2 == 0) {
cout << n << " is not extremly odd\n";
} else {
cout << n << " is extremely odd\n";
}
} while (true);
cout << "bye...\n";
return EXIT_SUCCESS;
}