Tuesday, November 24, 2015

Ordinal Number Generator in C++

A program that I wrote using C++ as my programming language that will ask the user to enter or give a number and then our program will generate the corresponding ordinal numbers. In this program I am using CodeBlocks 8.02 as my editor and Dev C++ as my compiler that is already integrated with CodeBlocks 8.02.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing

// ordinal.cpp
// Written By: Mr. Jake R. Pomperada, MAED-IT
// Tools : CodeBlocks 8.02
// Date  : November 24, 2015


#include <iostream>

using namespace std;

int test(int i) {

char *message;
int a=0, mod100 = 0, mod10 = 0;

cout << "\n";
for (a=1; a<=i; a++) {

 mod100 = (a % 100);
 mod10 = (a % 10);

if (mod10 == 1 && mod100 != 11) {

   message= "st";

} else if  (mod10 == 2 && mod100 != 12) {
 message="nd";
}
else if  (mod10 == 3 && mod100 != 13) {
message= "rd";
} else {
 message= "th";
 }
 cout <<" " << a << message << " ";
}

}

main(){

  int number=0;

  cout << "\n";
  cout <<"\t Ordinal Number Generator in C++";
  cout << "\n\n";
  cout << "Enter a Number : ";
  cin >> number;

  test(number);

  cout <<"\n\n";
  cout << "End of the Program";
  cout << "\n\n";
}



No comments:

Post a Comment