0

I'm trying to input values into an array and trying to do other things with the values. But for some reason the for loop only executes it self 3 times before spitting out random numbers

Heres the code:

using System;
using static System.Console;

namespace Chapter6._2
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] pricesList = new int[9];
            for (int i = 0; i < pricesList.Length; i++)
            {
                pricesList[i] = Convert.ToInt32(Read());
            }

            for (int i = 0; i < pricesList.Length; i++)
            {
                Write(pricesList[i] + " ");
            }
        }
    }
}

I don't know what I am doing wrong but my array does not have these following numbers it keeps outputting...

Heres what the last output just generated after I entered in 3 numbers.

2  <---
3  <--- I inputted these numbers
5  <---
50 13 10 51 13 10 53 13 10 <--- ???? This is what came out after ????
Avenius
  • 21
  • 7
  • [`Console.Read`](https://learn.microsoft.com/en-us/dotnet/api/system.console.read) returns an `int` representation of a single `char`. Try using `ReadLine` instead. – madreflection Feb 25 '20 at 04:11
  • @madreflection I feel dumb, thank you. – Avenius Feb 25 '20 at 04:12
  • It's okay. Just make sure you read the documentation for each method the first time you use it so you understand how it works. I've added a link to Read on my first comment. – madreflection Feb 25 '20 at 04:12

0 Answers0