Using array to find the score for a class - CSharp Language Basics

CSharp examples for Language Basics:Array

Description

Using array to find the score for a class

Demo Code

using System;/*from   w  ww.j  a  va  2s  . c  om*/
public class ClassScore
{
   public static void Main()
   {
      int [] scores = new int[30];
      int ttl = 0;
      System.Random rnd = new System.Random();
      Console.Write("Initializing scores.");
      for( int i = 0; i < 30; i++ )
      {
         scores[i] = (int) ((rnd.NextDouble() * 100) + 1);
         Console.Write(".");
      }
      Console.WriteLine("...done.\n");
      for( int i = 0; i < 30; i++ )
      {
         Console.WriteLine("Student {0} score: {1}", i+1, scores[i]);
         ttl += scores[i];
      }
      Console.WriteLine("Average Score = {0}", (ttl/20));
   }
}

Result


Related Tutorials