Start New Discussion within our Software Development Community

I am working on a program with the following requirements:

Write a program to calculate the average of all scores entered between 0 and 100. Use a sentinel-controlled loop variable to terminate the loop. After values are entered and the average calculated, test the average to determine whether an A, B, C, D, or F should be recorded. The scoring rubric is as follows:

A—90-100; B—80-89; C—70-79; D—60-69; F < 60

Here is what I have so far:

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

namespace PRG205_FinalAssessment_Doyle
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] marks;
            int minput = 1, counter = 0, total = 0;
            float aveg = 0.0f;
            String Gradeletter = "C";
            marks = new int[100];
            Console.WriteLine("Enter Student Grade");
            while (minput > 0)
            {
                minput = Convert.ToInt32(Console.ReadLine());
                if (minput >= 0)
                {
                    marks[counter++] = minput;
                    total += minput;

                    Console.WriteLine("Enter student grade or any negative value to calculate average");

Don't forget closing braces. Read your assignment very good, you don't use a sentinel value.
Here is what I quickly made of it so far.

int[] marks;
            int minput = 1, counter = 0, total = 0;
            float average = 0.0f; //try to alway use meaningful names so, no 'aveg' 'a' etc;

            int sentinel = 999;
            marks = new int[100];
            Console.WriteLine("Enter Student Grade");
            Console.WriteLine("Type 999 to end.");
            //Collect marks and total
            minput = Convert.ToInt32(Console.ReadLine());
            while ((minput >= 0) && (minput <= 100) && (minput != sentinel))
            {
                marks[counter++] = minput;
                total += minput;
                minput = Convert.ToInt32(Console.ReadLine());
            }
            //TO DO: calculate average and grade here
                    ReadKey();

One other thing, afaiks you did not compile. Try to d that inbetween as often as possible.

This article has been dead for over six months. Start a new discussion instead.