Answer to Question #267994 in C++ for Numa

Question #267994

Write a program that contains a function that displays “Welcome to CS127-8L!” Then, it asks for a double value such as 25.36, 100.02 etc. The maximum is 1000. Getting the double value must be done in a function as called by the main function. Then the main function displays the value in words.


1
Expert's answer
2021-11-18T15:17:13-0500
#include <iostream>
using ​namespace std;


string ​first[] = { "", "one ", "two ", "three ", "four ",
                 "five ", "six ", "seven ", "eight ",
                 "nine ", "ten ", "eleven ", "twelve ",
                 "thirteen ", "fourteen ", "fifteen ",
                 "sixteen ", "seventeen ", "eighteen ",
                 "nineteen " };
string ​second[] = { "", "", "twenty ", "thirty ", "forty ",
                 "fifty ", "sixty ", "seventy ", "eighty ",
                 "ninety " };
 string figuresToWords(int  number, string temp)
{
    string results = "";
  
    if (number > 19)
        results += second[number / 10] + first[number % 10];
    else
        results += first[number];
 
   
    if (number)
        results += temp;
 
    return results;
}


string final_convert(long number)
{


   
    string results;
 
    
    results += figuresToWords((number / 10000000), "crore ");
 
    
    results += figuresToWords(((number / 100000) % 100), "lakh ");
 
   
    results += figuresToWords(((number / 1000) % 100), "thousand ");
 
    
    results += figuresToWords(((number / 100) % 10), "hundred ");
 
    if (number > 100 && number % 100)
        results += "and ";
 
    
    results += figuresToWords((number % 100), "");
 
    return results;
}
 


int main()
{
		cout<<"Welcome to CS127-8L!\n";
   cout<<" Enter a double value:\n";
    long number;
    cin>>number;
 
    
    cout <<"That is "<< final_convert(number) << endl;
 
    return 0

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS