-3

I have some code below that is almost finished, but the last thing I want to do is for the console app to display the number they have gotten from the user

EX: if user input 1, 3, 5 the console will display

The number you have inserted are:

  1. One

  2. Three

  3. Five

Is it possible to do that ?

Thanks

static void Main (string []args)
        {
            string again;
            do
            {
                Console.Clear();
                Console.WriteLine("Insert Random number");
                int number = int.Parse(Console.ReadLine());

                Console.WriteLine("Would you like to Insert another number ?(Enter Y for yes /Enter any other key to exit)");
               again = Console.ReadLine();
            } while (again == "Y");


            Console.WriteLine("The number you have inserted are: ");


            Console.ReadKey();
        }
Aaron Jones
  • 1,140
  • 1
  • 9
  • 26
  • "Is it possible?" Of course it's possible. You need to store the user's input in some sort of list (like, perhaps, a `List`), and then at the end, iterate over the entries in the list and display them, or join the entries in the list into a string (with, perhaps, `string.Join`). Stack Overflow is not a code-writing service. Please attempt to solve the problem on your own and feel free to ask a question if you have a specific issue with implementing your solution. – Daniel Mann Apr 10 '20 at 15:52
  • 1
    if i understand correctly, maybe this [answer](https://stackoverflow.com/questions/3213/convert-integers-to-written-numbers) will help – Mohammed Sajid Apr 10 '20 at 15:55
  • 1
    Of course, if your requirement is to translate an Arabic numeral (such as "1") to an alphabetic representation of that number (such as "One"), then you are looking at a **much** different problem, with a lot of interesting challenges around localization and translating the number into text, depending on the scope of the problem. For example, translating "1,001,010" into "one million one thousand ten" is actually quite tricky. – Daniel Mann Apr 10 '20 at 15:56

1 Answers1

1

First, you need a place to keep all the numbers you collected. Given this code, you may be expected to use an array, but real code is more likely to use a generic List<int>. Declare it near the beginning of the Main method like this:

List<int> numbers = new List<int>();

Add each number to it after Parse()-ing like this:

numbers.Add(number);

Then, in between the final WriteLine() and ReadKey() calls, you need to loop through the collected numbers:

int i = 0;
for (int i = 0; i < numbers.Length; i++)
{
    Console.WriteLine($"{i+1}. {numbers[i]}");
}

What you won't be able to do in a simple way is convert the digit 1 to the text value One. There's nothing built into C# or .Net to do that part for you. Since this code looks like a learning exercise, I'll leave you to attempt that part on your own.

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
  • Thank you for the answer, this array is probably what i need my real assignment is actually to record a dish user want to eat and then display it as a full course menu but simplified it should look like that question but the structure shouldn't be that different right ? – Suriadi Chandra Apr 10 '20 at 16:24