im supposed to write a code that you prompt to enter 10 different grades then drop the minimum value, while computing the average of the remaining 9. I'm getting infinity as the answer when I run the program so I know my min is messed up, somewhere but i cant find it can anyone help?

using System;

namespace gradeblaster
{
   class Program
   {
      public static void Main(string[] args)
      {
         getValues();
      } // end Main
      static void getValues()
      {
         double total;
         double gradeCounter;
         double grade;
         double average;
         double min = Double.MinValue;

         total = 0;
         gradeCounter = 1;
         {
            while (gradeCounter <= 10) // while loop
            {
               Console.Write("Enter grade: ");
               grade = Convert.ToDouble(Console.ReadLine());
               total = total + grade - min;
               gradeCounter = gradeCounter + 1;

               average = (total - min) / 9;
               Console.WriteLine("\nAfter the last score is dropped, the class average is {0}", average);
            }
         }
      }
   } // end class
} // end namespace

Recommended Answers

All 5 Replies

double.MinValue is -1 divided by 10^300 or so.
Line 17 of your code is OK, but in line 26 and 29 you are substracting this value two times(x 10) from your total. What you have to do is after every input of a grade check if that input is smaller than min. If it is assign it to min. Make your total, don't substract min here! After 10 times min will now contain the smallest input.
Put lines 29 and 30 outside the while loop.
Succes!

If I understand the question correctly you need to remove the lowest value from the ten inputs and then average the remaining nine values.

Currently you are not doing that as the min is never changed from Double.MinValue (-1.7976931348623157E+308 <see the exponent>).

I think you need to add all the grades together and watch for the lowest grade, remove that from the total, then calculate the avereage by dividing by nine. Somthing like this:

double min = double.MaxValue;
            
            //...
            //...

            while (gradeCounter <= 10) // while loop           
            {               
                Console.Write("Enter grade: ");               
                grade = Convert.ToDouble(Console.ReadLine());
                if (grade < min) min = grade;
                total += grade;             
                gradeCounter = gradeCounter + 1;           
            }

            average = (total - min) / 9;
            Console.WriteLine("\nAfter the last score is dropped, the class average is {0}", average);

You are right privatevoid, for a min-function you have to test on the maxvalue of course! Thanks for reminding.

thanks guys........i dont know why i never thought of asking anyone for help at the beginning of the semester then i wouldn't be so behind!

We're all learning, and we're all here to help each other.
Welcome to Daniweb, as long as you show a willingness to learn and make an effort for yourself we will always be happy to help you :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.