Add to Favorites    Make Home Page 4184 Online  
 Language Categories  
 Our Services  

Home » C++ Home » Beginners / Lab Assignments Home » Convert a number into words

A D V E R T I S E M E N T

Search Projects & Source Codes:

Title Convert a number into words
Author Vikram Bhat
Author Email vrb1001 [at] yahoo.com
Description This program converts a number into words.
It works only(!) for numbers less than 100 crore, though this limit can be extended using the same logic.Can be used in billing programs and the like, with a few minor changes (like adding "only" at the end) The program is shorter other such programs and the logic is really elegant.

Category C++ » Beginners / Lab Assignments
Hits 371129
Code Select and Copy the Code
#include <conio.h> // For getch() function only #include <iostream> using namespace std; void numword1(int); void numword2(int); int main() { long unsigned int number,temp; int mult,i,digit,digits,last_two,hundred,thousand,lakh,crore; digits=last_two=hundred=thousand=lakh=crore=0; cout<<"Enter a number(lesser than 99,99,99,999) "; cin>>number; if(number>999999999) { cout<<"Number out of range!"; getch(); exit(0); } if(number==0) { cout<<"Zero"; getch(); exit(0); } temp=number; digit=number%10; // Extracting last two digts last_two=digit; number=number/10; digit=number%10; last_two=(digit*10)+last_two; number=number/10; // Extract hundreds digit=number%10; hundred=digit; number=number/10; // Extract thousands digit=number%10; thousand=digit; number=number/10; digit=number%10; thousand=(digit*10)+thousand; number=number/10; // Extract lakhs digit=number%10; lakh=digit; number=number/10; digit=number%10; lakh=(digit*10)+lakh; number=number/10; // Extract crores digit=number%10; crore=digit; number=number/10; digit=number%10; crore=(digit*10)+crore; while(temp!=0) // Calculate number of digits in the number { temp=temp/10; digits++; } cout<<"The number in words is: "; // Printing the number in words if(digits>=8) { numword2(crore); cout<<"crores "; } if(digits>=6) { if(lakh!=0) { numword2(lakh); cout<<"lakh "; } } if(digits>=4) { if(thousand!=0) { numword2(thousand); cout<<"Thousand "; } } if(digits>=3) { if(hundred!=0) { numword2(hundred); cout<<"Hundred "; } } numword2(last_two); getch(); return 0; } void numword1(int num) { switch(num) { case 0: break; case 1: cout<<"One "; break; case 2: cout<<"Two "; break; case 3: cout<<"Three "; break; case 4: cout<<"Four "; break; case 5: cout<<"Five "; break; case 6: cout<<"Six "; break; case 7: cout<<"Seven "; break; case 8: cout<<"Eight "; break; case 9: cout<<"Nine "; break; case 10: cout<<"Ten "; break; case 11: cout<<"Eleven "; break; case 12: cout<<"Twelve "; break; case 13: cout<<"Thirteen "; break; case 14: cout<<"Fourteen "; break; case 15: cout<<"Fifteen "; break; case 16: cout<<"Sixteen "; break; case 17: cout<<"Seventeen "; break; case 18: cout<<"Eighteen "; break; case 19: cout<<"Nineteen "; break; } return; } void numword2(int num) { if(num>=90) { cout<<"Ninety "; numword1(num-90); } else if(num>=80) { cout<<"Eighty "; numword1(num-80); } else if(num>=70) { cout<<"Seventy "; numword1(num-70); } else if(num>=60) { cout<<"Sixty "; numword1(num-60); } else if(num>=50) { cout<<"Fifty "; numword1(num-50); } else if(num>=40) { cout<<"Fourty "; numword1(num-40); } else if(num>=30) { cout<<"Thirty "; numword1(num-30); } else if(num>=20) { cout<<"Twenty "; numword1(num-20); } else numword1(num); return; }

Related Source Codes

Script Name Author
Moving ball screen saver karlmarx
The Classic Game of Snake & Ladder Lakshmi Narayana .A
Railway seat reservation question which comes in sapient VyomWorld
To calculate percentile Ravi Mathur
Send to folder ANIMESH SAHU
Analog clock and calendar Nazia & Rida
HIGH/LOW GAME MOLLY ARORA
Data structure (stack Implimentation) Swapnil B Adsure
Memory Game AnirudhSanyal
Easy Calc Anirudh Sanyal
GK Quiz Anirudh Sanyal
Hangman Game Manish Jain
Snakeman Manish Jain
Full month Calendar Nigi
Cursor shapes nigi

A D V E R T I S E M E N T




Google Groups Subscribe to SourceCodesWorld - Techies Talk
Email:

Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

New! Click here to Add your Code!


ASP Home | C Home | C++ Home | COBOL Home | Java Home | Pascal Home
Source Codes Home Page

 Advertisements  

Google Search

Google

Source Codes World.com is a part of Vyom Network.

Vyom Network : Web Hosting | Dedicated Server | Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

Sitemap | Privacy Policy | Terms and Conditions | Important Websites
Copyright ©2003-2024 SourceCodesWorld.com, All Rights Reserved.
Page URL: http://www.sourcecodesworld.com/source/show.asp?ScriptID=551


Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions | Quick2Host Review