#include #include using namespace std; int main() { cout << "Please input a non-negative whole number: "; int n {0}; cin >> n; if (!cin) { cerr << "Sorry, that wasn't a number.\n"; return EXIT_FAILURE; } if (n < 0) { cerr << "Sorry, the number can't be negative.\n"; return EXIT_FAILURE; } int lastDigit {n % 10}; //the rightmost digit of n int lastTwoDigits {n % 100}; cout << "The ordinal form of " << n << " is " << n; if (11 <= lastTwoDigits && lastTwoDigits <= 19) { //in the teens cout << "th"; } else if (lastDigit == 1) { cout << "st"; } else if (lastDigit == 2) { cout << "nd"; } else if (lastDigit == 3) { cout << "rd"; } else { cout << "th"; //none of the above } cout << ".\n"; //Period at the end of the sentence. return EXIT_SUCCESS; }