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
which programming language?
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.
c++
What does a switch do?
lol is this class about AI??
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).
@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.
@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.
Join our real-time social learning platform and learn together with your friends!