Quantcast
Channel: User BobbyShaftoe - Stack Overflow
Viewing all articles
Browse latest Browse all 45

Answer by BobbyShaftoe for Two types of array one is string and the other is int, i want to display all the user input values but it print only the last input not all?

$
0
0

You are not incrementing the index variable. I have incremented it. This is not really the best way to do this but I don't entirely understand what exactly you want to do. I hope this modification helps you see the difference.

namespace Test2{    class Program    {        static void Main(string[] args)        {            string[] Namen = new string[5];            int[] Lefftijd = new int[5];            int index=0;            for(int i = 0; i<Namen.Length;i++)            {                Console.Write("Geef de naam : ");                Namen[index++] = Console.ReadLine();            }            index = 0;            for(int j = 0 ; j < Lefftijd.Length; j++)            {                Console.Write("Geef de leeftijd : ");                Lefftijd[index++] = Convert.ToInt32(Console.ReadLine());            }            Console.WriteLine("De namen zijn  "+ Namen.Length +" en aantal leftijden zijn : "+ Lefftijd.Length);            Console.WriteLine();            Console.WriteLine("De naam is : "+ Namen[index] +" De leftijd is : "+ Lefftijd[index]);            Console.ReadLine();        }    }}

Viewing all articles
Browse latest Browse all 45

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>