Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 131,709 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,395 people online right now. Registration is fast and FREE... Join Now!




Figures in Words and Solution

 
Reply to this topicStart new topic

Figures in Words and Solution, am i rite

castro
post 19 Nov, 2005 - 11:41 AM
Post #1


New D.I.C Head

*
Joined: 12 Nov, 2005
Posts: 9


My Contributions


i want to write a program to accept as an input numbers not more than 999 999 999 and out put in words say if x= 300 then cout<< three hundred
this is my solution hope it works

CODE

#include<iostream>
#include<cstring>
using namespace std;
void millions();
void thousands();
void  hundreds();
int num,n,rec1,rec2,max,rec3[9],store,i,j,rec4[9];
char tenz[12][6]={"zero","one","two","three","four","five","six","seven","eight","nine","ten"};        
char out[100][6];
int main()
{
    do
    {
 cout<<"Enter number of digits";
 cin>>n;
    }while(n>=9);
    max=n;
    for(i=0;i<n;i++)
    {
 cout<<"Enter numbers rec1["<<i+1<<"]:";
 cin>>rec4[i];
    }
   for(i=0;i<max;i++)
   {
       store = rec4[i];
 for(int x=0;x<=max;x++)
         strcpy(out[i],tenz[store]);
   }
   i=0;
   if (max>6)
    millions();
   else if (max>3)
    thousands();
   else
   hundreds();
   return 0;
}    
void millions()
{
 
   if (max==9)
   {
       cout<<out[i]<<"Hundred and "<<out[i++]<<"-ty  "<<out[i+2]<<"  millions,";
       max=max-3;
       i=i+3;
       thousands();
   }    
   else if (max==8)
   {
       cout<<out[i]<<"-ty  "<<out[i+1]<<"  millions,";
       max=max-2;
       i=i+2;
       thousands();
   }
   else
   {
       cout<<out[i]<<"  million,";
      max = max-1;
      i++;
      thousands();
  }
}
void thousands()
{
   if (max==6)
   {
       cout<<out[i]<<"  hundred and "<<" "<<out[i++]<<"-ty  "<<out[i+2]<<"   thousand, ";
       max= max-3;
       i=i+3;
       hundreds();
   }
   else if (max==5)
   {
    cout<<out[i]<<"-ty"<<out[i+1]<<"thousand, ";
       max=max-2;
       i=i+2;
       hundreds();
   }
   else
   {
       cout<<out[i]<<"  thousand,";
      max = max-1;
      i++;
       hundreds();
    }
}
void hundreds()
{
    if(max==3)
{
    cout<<out[i]<<"  hundred and "<<out[i++]<<"-ty  "<<out[i+2];
}
else if(max==2)
{
  cout<<out[i]<<"-ty  "<<out[i++];
}
else
cout<<out[i];
}
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/20/08 09:32AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month