Alright I have a school assignment I had to create a loop to accept grade percentages from 0 to 100 and it needs to give the average percentage and letter grade, this is what I have but it is not working correctly, it always gives an F and no percentage.

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

namespace Grader
{
    class Grader
    {
        public static void Main(string[] args)
        {
            //initialize variable
            String userInput = ""; 
            int addedGrades = 0, intValue;

            //give instructions to the user
            Console.WriteLine("Please enter your student's grades.");
            Console.WriteLine("\nOnce you have finished enter -100 to stop.");
            Console.WriteLine("\nEnter -100 to exit the program");

            //starts the read process
            userInput = Console.ReadLine();  

            //while loop parameters
            while (userInput != "-100")
            {
                intValue = Convert.ToInt32(addedGrades);
                addedGrades += intValue;
                Console.WriteLine("Enter -100 to exit");
                userInput = Console.ReadLine();
            }

            //create if statements to determine letter grade
            int averageGrades = addedGrades / 100;
                if ((averageGrades >= 0) && (averageGrades <= 59))
                {
                    Console.WriteLine("Total grade = F");
                    Console.WriteLine("Total percent = ", averageGrades);
                }
                else
                    if ((averageGrades >= 60) && (averageGrades <= 69))
                    {
                        Console.WriteLine("Total grade = D");
                        Console.WriteLine("Total percent = ", averageGrades);
                    }
                    else
                        if ((averageGrades >= 70) && (averageGrades <= 79))
                        {
                            Console.WriteLine("Total grade = C");
                            Console.WriteLine("Total percent = ", averageGrades);
                        }
                        else
                            if ((averageGrades >= 80) && (averageGrades <= 89))
                            {
                                Console.WriteLine("Total grade = B");
                                Console.WriteLine("Total percent = ", averageGrades);
                            }
                            else
                                Console.WriteLine("Total Grade = A");
                                Console.WriteLine("Total percent = ", averageGrades);
            Console.Read();
        }
        
    }
}

Any help is appreciated. Thanks.

Also, there seems to be some confusion as to the count of the number of grades and the actual "sum" of the grades.

Step through this in debug mode and you will see.

Change line 27 into intValue = Convert.ToInt32(userInput);
Unless you type something like "I get bored watching an F" and type nothing but integers it should work alot better.

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