Question: CONVERTING DIGITS INTO WORDS ASSIGNMENT FOR C# IN VISUAL STUDIO: My first suggestion: If you were a manager, have you thought about how you might

CONVERTING DIGITS INTO WORDS ASSIGNMENT FOR C# IN VISUAL STUDIO:

My first suggestion: If you were a manager, have you thought about how you might describe to your employee how to solve the problem? For example:

1. Start with a number like 9876.

2. Pick off the first digit, 9, and convert it to a text equivalent, like 9 = "nine".

3. Add the word "thousand" next.

4. Pick off the second digit, 8, and convert it the same way, like 8 = "eight".

5. Add the word "hundred" after it.

6 And so on for 7 and 6.

So, you need a way to grab the number from the Console:

int toConvert = int.Parse(Console.ReadLine());

Pick off the first digit:

int thousands = toConvert / 1000 // integer division gives you 9

Pick off the remainder to continue toward getting the next digit:

int thousandsRemainder = toConvert % 1000 // gives you 876

Now, do the same as before to get hundreds:

int hundreds = thousandsRemainder / 100 //gives you 8

and get the next set of digits in a similar fashion. The numbers from 11 through 19 will need to be handled a little differently.

Finally, if you had a string array as follows:

string[] numbers = new numbers[] {"zero", "one", "two", "three", ... "eighteen", "nineteen"}

You can translate integers to strings as follows:

string result = numbers[thousands] + " thousand " + numbers[hundreds] + " hundreds " + ...

giving:

result = "nine thousand eight hundred ..." // you do the rest!

You also need an array that holds the values: "twenty", "thirty", ... , "ninety".

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!