c++ HELP

My Teacher Assigned An Assignment And I Need A Little Help. He Wants Us To Write a program that takes a command line argument N and prints out the first N ordinals, followed by Hello. In Other Words... This Is What He Wants...

1st Hello
2nd Hello
3rd Hello
4th Hello
5th Hello
...
10th Hello
11th Hello
12th Hello
13th Hello
...
20th Hello
21st Hello
22nd Hello

Only Problem Is I Don't Know The Code That Would Work To Change The "st", "nd", "rd", or "th" for printing the ith Hello." Any Help???

#include <iostream>
using namespace std;
int main ()
{
 int n,mod_test;

 cout << "Enter the ending number > ";
 cin >> n;
 cout << "\n";
 while (n>0) 
 
 {
      {
        mod_test = n%10;        
        if (mod_test==0) 
        {
    cout << n << "th hello \n ";
         }
    else if (mod_test==2)
    {
    cout << n << "nd hello \n ";
    }
    else if(mod_test==1)
    {
    cout << n << "st hello \n ";
    }
    else if (mod_test==3)
    {
    cout << n << "rd hello \n ";
    }
    else
    {
    cout << n << "th hello \n ";
    }
  }
     --n;    
 }
 system("pause"); 
 return 0;
}



I'm Using That But That Writes "11th" As "11st" And "12th" As "12nd" And "13th" As "13rd" How Do I Fix This???
1
2
3
4
5
6
//...
    if (mod_test==0 || n==11 || n==12 || n==13) 
    {
        cout << n << "th hello \n ";
    }
//... 
Last edited on
Topic archived. No new replies allowed.