Latest topics
Convert from number to word
Page 1 of 1
Convert from number to word
convert a number to word like this
192 to one hundred ninety two
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;
}
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|
Thu Dec 23, 2021 11:20 pm by Optitech
» Sf Car Rental Agency - Perkhidmatan Kereta Sewa Shah Alam
Wed Sep 09, 2015 2:48 am by sksportcar
» Homestay Di Kota Bharu
Sun Jan 25, 2015 10:52 pm by sksportcar
» Sf Car Rental Agency - Kereta Sewa Shah Alam
Tue Aug 05, 2014 8:54 am by sksportcar
» Bahasa Jepun: Ayat Seharian,Hari,Haribulan & Nombor
Mon Sep 23, 2013 8:43 pm by foxfoxer
» Tips nak hapuskan virus secara manual [On updates]
Tue Mar 19, 2013 8:38 am by Optitech
» Teknik defense dari virus and spyware [Auto]
Thu Jul 21, 2011 2:53 am by Optitech
» Virus shortcut kat pendrive
Thu Jul 21, 2011 12:27 am by Optitech
» Admin Kembali dengan Menyengat
Wed Jul 20, 2011 1:59 pm by Optitech