Henry Lhteenmaki

Henry Lhteenmaki

  • NA
  • 13
  • 12.2k

indexOutOfRangeExeption was unhadled error

Dec 21 2011 12:24 PM
Hi !

I have made this program , and for some reason I got a error in line 33 that says :indexOutOfRangeExeption was unhadled.

could you please, explain to me what mistake I have done  in the program .

Br

Henry

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Assignment3
{
    class Program
    {
        static void Main(string[] args)
        {
            string name, message = " ";
            int average = 0 ;

            //Users names

            Console.WriteLine("Enter you name");
            name = Console.ReadLine();
           
            // Declare variables the type array

            string[] var = { "first", "second", "third" };
            int[] scores = new int[3];
           

            // loop trought the arrays

            for (int i = 1 ; i <= var.Length; i ++)  {
               
                 try
                {
                    Console.WriteLine("Enter your {0}, score", var[i]);
                    scores[i] = int.Parse(Console.ReadLine());
                    average += scores[i]/3;
                }

                catch (FormatException) {

                    Console.WriteLine("the {0}, is Not a numeric value ", scores[i]);
               
               
                }
            }
          


            // Testing the average

            if (average >= 90 && average <= 100)
            {
           
                message = "Wow, you did great";
            }

            else if (average >= 80 && average <= 89)
            {
           
                 message = "Pretty good!";
            }

            else if (average >= 75 && average <= 79)
            {
           
                message = "That was close....";
           
            }

            else if (average < 75)
            {

                message = "Better luck next time";
           
            }


           
           
            Console.WriteLine("Hi {0}, {1}", name, message);
            Console.ReadLine();
            return;
            }
        }
    }


Answers (5)