Paul Shannon

Paul Shannon

  • NA
  • 3
  • 1.2k

Array with barchart question.

May 26 2013 4:53 PM
Hi, I was just wondering if anyone could help me with this problem I have. I want to create a bar chart format, to display how many scorers are in each part of the grade array. I want to increment the bar chart with a * everytime a number goes in to the grades array. I have the code mostly done, just can't seem to get the bar chart to work. Any help would be greatly appreciated, thank you.

  static void Main(string[] args)
        {

            Console.WriteLine("Enter the mark you received, enter -999 to quit");
            int mark = Convert.ToInt32(Console.ReadLine());
            

            int[] grade = new int[5];
            while (mark != -999)
            {
                if (mark >= 70 && mark <= 100)
                {
                    grade[0]++;
                   
                }
                else if (mark >= 60 && mark <= 69)
                {
                    grade[1]++;
                   
                }

                else if (mark >= 50 && mark <= 59)
                {
                    grade[2]++;
                    
                }
                else if (mark >= 40 && mark <= 49)
                {
                    grade[3]++;
                   
                }
                else if (mark >= 0 && mark <= 39)
                {
                    grade[4]++;
                    
                }
                Console.WriteLine("Enter the mark you received, enter -999 to quit");
                mark = Convert.ToInt32(Console.ReadLine());
            }

            for (int i = 0; i < grade.Length; i++)
            {
                Console.WriteLine( "{0,-15} {1,-15}", grade[i], "*");
            }
            Console.ReadLine();
        }

Answers (2)