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

namespace ConsoleApplication1
{
    class While
    {
        private double sum;

        public void Star()
        {
            WriteProgramInfo();
            ReadInPutAndSumNumbers();
            ShowResults();
        }
        private void ReadInPutAndSumNumbers()
        {
            double num = 0.0;
            bool done = false;
            while (!done)
            {
                {

                }
            }
        }
        private void WriteProgramInfo()
        {
            Console.WriteLine("\n\n ++++++ Finnish input type 0 ++++++");

        }
        private void ShowResults()
        {
        }

    }

}

hi.

I cant figuer out how to do this.

When the program start i can put in as meny numbers that i want in to it until i put in 0 then it will finnish and i can sum up the values but i dont know how im going to do it. i know how to do while loops but not to to like this whit out saying how many times it going to put it out

so can any one explane to my how to do it? its a school work but i dont need to send it in but i need to learn how to do it if im going to do same things like this in the future

no but i only have this in it:

While obj = new While();
obj.Star();

Look at something like this:

using System;

namespace DW_409519_CS_CON
{
   class Program
   {
      static void Main(string[] args)
      {
         string strData = "";
         int intData = 0;

         while (!strData.Equals("0"))
         {
            Console.WriteLine("Enter a number.  Enter 0 to quit");
            strData = Console.ReadLine().Trim();

            if (strData.Equals("0"))
            {
               continue;
            }

            if (!int.TryParse(strData, out intData))
            {
               Console.WriteLine("Not a good number: " + strData);
               continue;
            }

            Console.WriteLine("Doing something with: " + strData);
            //Add code here to do something...
         } 
      }
   }
}

Edited 4 Years Ago by thines01: clarity

thx for it but om going only to put it in my While class and only have
While obj = new While();
obj.Star();

in the main

thx for it but om going only to put it in my While class and only have
While obj = new While();
obj.Star();

in the main

He wasn't writing your program for you. He was giving you a very simple and clear implementation of how your program is supposed to function. The simplest way for him to give you a complete program was to implement the whole thing in Main().

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

namespace ConsoleApplication1
{
    class While
    {
        private double sum=0;

        public void Star()
        {
            WriteProgramInfo();
            ReadInPutAndSumNumbers();
            ShowResults();

        }
        private void ReadInPutAndSumNumbers()
        {
            double num = 0.0;
            bool done = false;
            while (!done)
            {
                Console.WriteLine("Enter the Number:");
                try
                {
                    num = Convert.ToDouble(Console.ReadLine().Trim());
                    sum += num;
                    if (num == 0)
                    {
                        done = true; 
                    }
                 }
                catch
                {
                    Console.WriteLine("Enter An Valid value");
                }
            }
        }
        private void WriteProgramInfo()
        {
            Console.WriteLine("\n\n ++++++ Finnish input type 0 ++++++");

        }
        private void ShowResults()
        {
            Console.WriteLine("\n\n ++++++ Finnished output type "+sum.ToString() +" ++++++");
        }


    }

}

Edited 3 Years Ago by Dani: Formatting fixed

Comments
Use code tags
Don't give whole solutions to homework problems
This article has been dead for over six months. Start a new discussion instead.