c# - Reading in values into Array -
this program asks user array size asks user enter in array values. problem having loop read in array values doesn't work properly. no matter value n
it sitll ask lot more inputs.
int n; console.writeline("enter how many values entering in"); n = convert.toint32(console.read()); int[] arr = new int[n]; console.writeline("enter values in"); (int = 0; < n; i++) { arr[i] = convert.toint32(console.read()); }
quick , easy fix:
use int.parse(console.readline())
in place of convert.toint32(console.read())
explanation:
you getting ascii value way doing it. example, if type in number 2
n
variable have been set 50
.
Comments
Post a Comment