This program is giving me a count up to 999. which is not what it is suppose to do. can someone tell me how to fix it. The question is as follow:

Write a program that allows the user to enter any number of integer values continuously (in any order) until the user enters 999. Display the sum of the values entered, not including 999.

static void Main()
    {
        int num= 1;

        Console.WriteLine("Please enter a number:");
        Console.ReadLine();


        while (num >1 || num < 999)
        {
            Console.WriteLine("The Sum of {0}", num);
            num = num + 1;
        }
    }
}

Edited 3 Years Ago by Dani: Formatting fixed

Hi,

You can use the code given below.

static void Main(string[] args)
        {
            int iNum = 0;
            int iSum = 0;
            
            while (iNum != 999)
            {
                Console.WriteLine("Please enter a number:");
                iNum = Convert.ToInt32(Console.ReadLine());
                if (iNum != 999)
                {
                    iSum = iSum + iNum;
                }
            }

            Console.WriteLine("The sum of the numbers is {0}", iSum);
            Console.ReadLine();
        }

Edited 5 Years Ago by saravind84: Add Comments

Thank you for the help. But i am getting a error.

The name 'convert' does not exist in the current context

I got it to work. i typed the as convert instead of Convert.
You Rock. Thank you.

This question has already been answered. Start a new discussion instead.