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

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -