c# - Find sum of elements of an array -
what calculations need find total?
else if (a =2) { totalcredit = new int[15]; console.writeline("please enter credits"); int = 0; (i = 0; < 15; i++) { int credit = convert.toint32(console.readline()); total + credit; } console.writeline(total); }
you need declare variable total ahead use , should before loop keep scope available after loop. more sum operation should corrected using += operator correct follows:
int total=0; (i = 0; < 15; i++) { int credit = convert.toint32(console.readline()); total += credit; } console.writeline(total);
Comments
Post a Comment