Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

JASdeep11 Group Title

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.

  • 2 years ago
  • 2 years ago

  • This Question is Closed
  1. onurtuna Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    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

    • 2 years ago
  2. JASdeep11 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    there are supposed to be up to 9 digits

    • 2 years ago
  3. Muhammad.Ateeq.Azam Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    #include<limits> #include <windows.h> #include <string> #include <iostream> 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!"<<endl; while(1) { system("color 5B"); int n; while((cout<<"\n\n Enter integer [till 9-didgits] : ")&&(!(cin>>n))){ cout<<"\n\t\tInvalid Input!"<<endl; cin.clear(); cin.ignore(numeric_limits<streamsize>::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"; } }

    • 2 years ago
  4. JASdeep11 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    @Muhammad.Ateeq.Azam my teacher wants me to use the switch statement to write this program

    • 2 years ago
  5. Muhammad.Ateeq.Azam Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    just use switch statements instead of if statements :)

    • one year ago
  6. JASdeep11 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    ok

    • one year ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.