fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main () {
  6. int yourPlace;
  7. int lastPlace;
  8. cout << "Your place: ";
  9. cin >> yourPlace;
  10. cout << endl << "Final place: ";
  11. cin >> lastPlace;
  12. cout << endl;
  13.  
  14. for (int i = 1; i <= lastPlace; i++) {
  15. if (i == yourPlace)
  16. break;
  17. if (i%100 == 11 || i%100 == 12 || i%100 == 13)
  18. cout << i << "th";
  19. else if (i%10 == 1)
  20. cout << i << "st";
  21. else if (i%10 == 2)
  22. cout << i << "nd";
  23. else if (i%10 == 3)
  24. cout << i << "rd";
  25. else
  26. cout << i << "th";
  27. if (i == lastPlace)
  28. cout << ".";
  29. else if (i == lastPlace - 1)
  30. cout << " and ";
  31. else
  32. cout << ", ";
  33. }
  34.  
  35. }
Success #stdin #stdout 0s 3464KB
stdin
5
20
stdout
Your place: 
Final place: 
1st, 2nd, 3rd, 4th,