#Strings problem

21 messages · Page 1 of 1 (latest)

long magnet
#

Problem:
Write a program to read a number and print the text of that number.

Exam1:
Enter a Number? 5843
Five Thousands Eight Hundreds Forty Three

Exam2:
Enter a Number? 8476362741
Eight billion four hundred seventy six million three hundred sixty two thousand seven hundred forty one

I was told to use recursion function as a hint

Any idea ?

obtuse pebbleBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

obtuse pebbleBOT
# peak lily !howto ask

@long magnet

How to Ask a Programming Question

Anyone can ask a question in our programming channels. Following the guide Writing The Perfect Question is recommended.

What to Post

State your problem clearly and provide all necessary details:

  • the relevant portion of your code, or all of it
  • the expected output
  • the actual output (or the full error)
    :trophy: Gold Standard: Minimal Reproducible Example
Where to Post

Provide the relevant code in the message, and format it nicely with a code block*. If it's too much for one message, you can upload it:

  • Compiler Explorer for most C and C++ snippets
  • OnlineGDB for interaction, debugging
    :no_entry: Do not post screenshots, let alone photos of your screen!
long magnet
#

Strings problem

peak lily
#

!hw

obtuse pebbleBOT
# peak lily !hw
Monke
We Don't Do Your Homework

Welcome to Together C & C++ :wave:

We won't do your homework for you (#rules) but we are happy to help you learn and point you in the right direction.

Please send what you have so far and ask a specific question.

native sail
narrow blade
#

yeah XD

#

the entire thing is wrong

peak lily
#

Isn't it also "fourty" instead of "forty"? Or is "forty" some AE spelling?

long magnet
#

idk whatever you got the idea

narrow blade
#

welp

native sail
#

i am a begginer,but my approach would be to make a function that sees where the digit is,and append the correct thing to it
if the digit is in the 4th place,append "thousand" or something
and continue for all digits

#

im sure theres a better way

long magnet
#

make sense ill think about it

peak lily
#

Recursion is really similar to induction proofs (math).
You have a big problem, but you always only chop off a single piece of that and reduce the problem to a similar, but simpler problem.
You can just consume digits from the right and for each number (or sometimes 2) you take off, you prepend the corresponding name to this/these digit/s, and after every 3 numbers you prepend the next "big word" (e.g. thousand, million, etc.)

long magnet
#

i see

#

needs time

obtuse pebbleBOT
#

This question is being automatically marked as stale.
If your question has been answered, type !solved.
If your question is not answered feel free to bump the post or re-ask.
Take a look at !howto ask for tips on improving your question.

long magnet