You are here:

C++/Please answer me sir

Advertisement


Question
Hello sir,
i would really appreciate it if you could help me in this project.I need to write a code in a source file,this code asks the user to enter a number for example 458,and then the code should convert these numbers to words,so it should write four hundred and fifty eight.
the maximum number reaches to 90 000 000,and it should uses as less memory as it can
please sir help me,and please try to make it as simple as you can...
Thank you very much sir...

Answer
include <cstdlib>
#include <iostream>
#include <string>
using namespace std;

int main(int argc, char *argv[])
{

 int inum;
 cout<<"enter the number";
 cin>>inum;
 int iquo, irem;
 iquo = inum/100;
 irem = inum%100;
 char *cdipp;
 cdisp = new char[200];
 if(irem >=10 && irem < 20)
 {
         switch (irem)
         {
         case 11:
         strcat(cdisp," eleven");

         break;
         case 12:
         strcat(cdisp," twelve");
         
         break;
         case 13:
         strcat(cdisp," thirteen");
         
         break;
         case 14:
         strcat(cdisp," fourtine");

         break;
         case 15:
         strcat(cdisp," fifteen");
         
         break;
         case 16:
         strcat(cdisp," sixteen");
         
         break;
         case 17:
         strcat(cdisp," seventeen");
         
         break;
         case 18:
         strcat(cdisp," eighteen" );
         
         break;
         case 19:
         strcat(cdisp," nineteen");
         
         break;
         }
    }
    if(irem >= 20)
    {
         switch (irem)
         {
         case 20:
         strcat(cdisp," twenty");

         break;
         case 30:
         strcat(cdisp," thirty");
         
         break;
         case 40:
         strcat(cdisp," fourty");
         
         break;
         case 50:
         strcat(cdisp," fifty");

         break;
         case 60:
         strcat(cdisp," sixty");
         
         break;
         case 70:
         strcat(cdisp," seventy");
         
         break;
         case 80:
         strcat(cdisp," eighty");
         
         break;
         case 90:
         strcat(cdisp,"ninenty" );
         
         break;
         }
         irem = irem %10;
         switch (irem)
         {
         case 1:
         strcat(cdisp," one");

         break;
         case 2:
         strcat(cdisp," two");
         
         break;
         case 3:
         strcat(cdisp," three");
         
         break;
         case 4:
         strcat(cdisp," four");

         break;
         case 5:
         strcat(cdisp," five");
         
         break;
         case 6:
         strcat(cdisp," six");
         
         break;
         case 7:
         strcat(cdisp," seven");
         
         break;
         case 8:
         strcat(cdisp," eight" );
         
         break;
         case 9:
         strcat(cdisp," nine" );
         
         break;
         }
         
       }
       irem = inum%1000;
       if( irem >= 100)
       {
         int itemp = irem/100
         switch (itemp)
         {
         case 1:
         strcat(cdisp," hundred");

         break;
         case 2:
         strcat(cdisp," twohundred");
         
         break;
         case 3:
         strcat(cdisp," threehundred");
         
         break;
         case 4:
         strcat(cdisp," fourhundred");

         break;
         case 5:
         strcat(cdisp," fifvehundred");
         
         break;
         case 6:
         strcat(cdisp," sixhundred");
         
         break;
         case 7:
         strcat(cdisp," sevenhundred");
         
         break;
         case 8:
         strcat(cdisp," eighthundred" );
         
         break;
         case 9:
         strcat(cdisp," ninehundred" );
         
         break;
         }
        }
       
   strcat(cdisp,"\n");;
   cout<<"the word is " << cdisp;
    
  
  
   system("PAUSE");
   return EXIT_SUCCESS;
}
Hi I have just provided the logic. I have not compiled the program. I have done it till hundred.

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


rakshitha

Expertise

Difficult questions related to C .

Experience

C ,vc ,opc ,windows CE, ActiveX

Education/Credentials
Masters in electrical engineering

©2016 About.com. All rights reserved.