anonymous
  • anonymous
Write a program that reads a whole number of up to nine digits and prints it in words. For example, the input 13247 ought to produce "thirteen thousand two hundred forty seven". i need a step-by-step explanation not the code.
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
schrodinger
  • schrodinger
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
Just make the program read the numbers in an array then calculate the length of the number - how many numbers are there? pritn the number in words as how many numbers are
anonymous
  • anonymous
there are supposed to be up to 9 digits
anonymous
  • anonymous
#include #include #include #include using namespace std; string num_to_text[] = { "", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen" }; string tens_to_text[] = { "", "", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety" }; string power_to_text[] = { "", "Thousand", "Million", "Billion" }; string padIfNeeded (string ans) { if ( ans == "" ) { return ""; } return " " + ans; } string translateHundred (int hundred_chunk) { if ( hundred_chunk < 20 ) { return num_to_text[ hundred_chunk ]; } int tens = hundred_chunk / 10; int ones = hundred_chunk % 10; return tens_to_text[ tens ] + padIfNeeded( num_to_text[ ones ] ); } string translateThousand (int thousand_chunk) { if ( thousand_chunk < 100 ) { return translateHundred( thousand_chunk ); } else { int hundreds = thousand_chunk / 100; int hundred_chunk = thousand_chunk % 100; return num_to_text[ hundreds ] + " Hundred" + padIfNeeded( translateHundred( hundred_chunk ) ); } } int main() { cout<<"\t\t\t Assalam-O-Alaikum!"<>n))){ cout<<"\n\t\tInvalid Input!"<::max(),'\n'); } cout<<"\n\t"; string number; bool is_negative = false; if ( n < 0 ) { is_negative = true; n *= -1; } int chunk_count = 0; while ( n > 0 ) { if ( n % 1000 != 0 ) { number = translateThousand( n % 1000 ) + padIfNeeded( power_to_text[ chunk_count ] + padIfNeeded( number ) ); } n /= 1000; chunk_count++; } if ( number == "" ) { number = "Zero"; } if ( is_negative ) { number = "Negative " + number; } cout << number << endl; cout<<"\n\n\t ----------------------------------------------------------\n\n"; } }

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
@Muhammad.Ateeq.Azam my teacher wants me to use the switch statement to write this program
anonymous
  • anonymous
just use switch statements instead of if statements :)
anonymous
  • anonymous
ok

Looking for something else?

Not the answer you are looking for? Search for more explanations.