JMTI - Student Forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Navigation
 Index
 Memberlist
 Profile
 FAQ
 Search
Latest topics
» Cara hubungi admin
Convert from number to word EmptyThu Dec 23, 2021 11:20 pm by Optitech

» Sf Car Rental Agency - Perkhidmatan Kereta Sewa Shah Alam
Convert from number to word EmptyWed Sep 09, 2015 2:48 am by sksportcar

» Homestay Di Kota Bharu
Convert from number to word EmptySun Jan 25, 2015 10:52 pm by sksportcar

» Sf Car Rental Agency - Kereta Sewa Shah Alam
Convert from number to word EmptyTue Aug 05, 2014 8:54 am by sksportcar

» Bahasa Jepun: Ayat Seharian,Hari,Haribulan & Nombor
Convert from number to word EmptyMon Sep 23, 2013 8:43 pm by foxfoxer

» Tips nak hapuskan virus secara manual [On updates]
Convert from number to word EmptyTue Mar 19, 2013 8:38 am by Optitech

» Teknik defense dari virus and spyware [Auto]
Convert from number to word EmptyThu Jul 21, 2011 2:53 am by Optitech

» Virus shortcut kat pendrive
Convert from number to word EmptyThu Jul 21, 2011 12:27 am by Optitech

» Admin Kembali dengan Menyengat
Convert from number to word EmptyWed Jul 20, 2011 1:59 pm by Optitech


Convert from number to word

Go down

Convert from number to word Empty Convert from number to word

Post  Optitech Fri Feb 12, 2010 1:57 am

convert a number to word like this
192 to one hundred ninety two



Code:

#include <cstdlib>
#include <iostream>

      using namespace std;
      const char* onesWord[] = {"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
      const char* tensWord[] = {"", "ten", "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety"};

      void disp(int num)
      {

      if(num == 0)
      {
      cout << "Zero" << endl;
      return;
      }

      if(num > 9999)
      {
      cout << "Number Out of Bounds, Please Try Again" << endl;

      return;
 
      }

      int thousands = num / 1000;
      int hundreds = num / 100;
      int tens = (num / 10) % 10;
      int ones = num %10;

      if(thousands > 0)
      cout << onesWord[thousands] << " Thousand ";
      if(hundreds > 0)
      cout << onesWord[hundreds] << " Hundred ";

      if(tens > 0)
      cout << tensWord[tens] << " ";
      if(ones > 0)
      cout << onesWord[ones];
      cout << endl;
      }
       
      int main(int argc, char *argv[])
      {
      cout << "Please Enter a Number\n";
      int entered = 0;
      cin >> entered;
      cout << "The Number Is: ";

      disp(entered);
      system("PAUSE");

      return EXIT_SUCCESS;
      }
Optitech
Optitech

Posts : 519
Join date : 2010-01-01
Age : 32
Location : ProxyFireZ

http://sembangseposen.blogspot.com

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum