Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

JASdeep11

  • 2 years ago

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 and i am supposed use the switch statement

  • This Question is Closed
  1. the_me
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    which programming language?

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

    The first thing to look at is the limits. You need 9 digits. This means that your words need to go up to 999,999,999 or [Nine Hundred and Ninety Nine] Million, [Nine Hundred and Ninety Nine] Thousand, [Nine Hundred and Ninety Nine]. And in the repeated section, there's more repetition... [Nine] Hundred and Ninety [Nine] Hopefully you see that you'll only need to store the words of the following types "one", "two", "three", ... "eleven", "twelve", "thirteen", ... [special case] "twenty", "thirty", "forty", ... "hundred", "thousand", "million", ... Once you have them stored, you just need to print them in the right order. This is where the switch comes in. For example: switch(number){ case 1: //print "one" break; } You may need multiple switches, depending on how you structure it.

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

    c++

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

    What does a switch do?

  5. Pradius
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    lol is this class about AI??

  6. bdean20
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    A switch is used in place of lots of ifs and elses, in practice. Instead of: if (number == 1){ //do something } else if (number==2){ //do something } You do this: switch(number){ case 1: //if number is 1, execute this code break; case 2: //if number is 2, execute this code break; } You'll potentially want to use both in different circumstances. A switch is definitely easier for multiple situations, especially if you want to execute the code for two options in only some of the cases (if you don't include break at the end of a case, it will run through until the end of the switch or the next break statement).

  7. teic85
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    @bdean20, thanks for the explanation. I don't fully understand it, because I know nearly nothing about computer science and programming languages. I've been trying to find sources online to learn about these topics: Open Study, Udacity, YouTube, Khan Academy; but, so far I've had a lot of trouble understanding because I am wholly unfamiliar.

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

    @bdean20 on youtube look up thenewboston and he has some preety good tutorial for c++, python, Java, and some others. I know that for Java it has helped me out a lot, and we use it for my class.

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

    • Attachments:

Ask your own question

Ask a Question
Find more explanations on OpenStudy

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.