#include <iostream> #include <string> using namespace std; int main () { int yourPlace; int lastPlace; cout << "Your place: "; cin >> yourPlace; cout << endl << "Final place: "; cin >> lastPlace; cout << endl; for (int i = 1; i <= lastPlace; i++) { if (i == yourPlace) cout << ""; // Had issues with break; but this works (not well) else if (i%100 == 11 || i%100 == 12 || i%100 == 13) cout << i << "th"; else if (i%10 == 1) cout << i << "st"; else if (i%10 == 2) cout << i << "nd"; else if (i%10 == 3) cout << i << "rd"; else cout << i << "th"; if (i == yourPlace) cout << ""; // Had issues with break; but this works (not well) else if (i == lastPlace || (lastPlace-1 == i && yourPlace == lastPlace)) cout << "."; else if (i == lastPlace - 1) cout << " and "; else cout << ", "; } }
5 20
Your place: Final place: 1st, 2nd, 3rd, 4th, 6th, 7th, 8th, 9th, 10th, 11th, 12th, 13th, 14th, 15th, 16th, 17th, 18th, 19th and 20th.