Home » questions » Write a C++ program to input a number between 20 to 99 and display its numbername?

Write a C++ program to input a number between 20 to 99 and display its numbername?

2006-08-05 04:51:56, Category: Programming & Design
If ,for example , we have input a number say 22, then it should display twenty two. Please help me immediately.

Answers

  1. 3dillusion

    On 2006-08-05 06:08:09


    Just seeing this program will not help u. U need to independently develop ur programming skills. First start with Numbers from 1->10 , then 1->100 and then try even more!!! This is the solution but i am not sure whether I am doing more Harm thn good. Try urself first. --------------------------------- That was a general disclaimer to warn. --------------------------------- The code: -------------- //A program to convert Number into Words // Works Upto 9 Billion ... // A Program by 3dillusion #include //#include #include char d1[][10]={" ","One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen",}; char d2[][10]={" ", "Ten","Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninety"}; char d3[][15]={"","Hundred and","Thousand and","Lakh and","Million and","Billion and"}; void test(long int); void ten(long int); void hun(long int); void thou(long int); void lakh(long int); void mill(long int); void bill(long int); void main() { long int num; cout<<"Enter the Number to be turned into Words : \n"; cout<<"Remember Do Not Enter Zero at front\nbecause C++ shall treat it as Octal No.\n\n\n\t\t\tThe Number\t:"; scanf("%ld",&num); cout<<"\nIn Words :\n"; if (num<0) { cout<<"Minus "; num=-num; } test(num); getch(); } void test(long int num) { long int copy=num; if (num<20) ten(copy); if (num>=20 && num <=99) ten(copy); if (num>=100 && num <=999) hun(copy); if (num>=1000 && num<100000) thou(copy); if (num>=100000 && num<=9999999) lakh(num); if (num>=10000000 && num<=999999999) mill(num); if (num>=1000000000) bill(num); } void ten(long int copy) { if (copy>=0 && copy <20) cout<
  2. fwiiw

    On 2006-08-05 05:58:22


    Not sure about C++ but you need two "Case" or sometimes called "Switch" statements. One for the "Ones name" and one for the "Tens name" In PHP it would look like this: $myNumber = 34; $tensValue = intval($myNumber/10) * 10 ; $onesValue = $myValue - $tensValue; switch ($onesvalue) { Case 0: $onesName = ""; break; Case 1: $onesName = "One"; break; ... keep going till you reach 9 ... } switch ($tensValue) { case 0: $tensName = ""; break; case 10: $tensName = "Ten"; break; ..... keep going to 90 .... } $fullname = $tensNalue . $onesName; This should be easy to translate to any language.