Hello

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

namespace ConsoleApplication1
{
    class WholeNumbersFor
    {
        private int numOfInPut;
        private int sum;

        public void start();
    
        WriteProgramInfo();
        ReadInPut();
        SumNumbers();
        ShowResults();
    }
    private void ReadInPut()
{

    Console.Write ("Number of Values to sum?");
    NumOfInPut = int.Parse(console.Readkey());
    console.Writeline();
}
    private void WriteProgramInfo()
{
    console.Writeline("\n\n ++++++ Summation of whole numbers ++++++");
    console.Writeline();

}
    private void SumNumbers()
{

    int index;
    int Sum = 0;

    for (index = 0; index < NumOfInPut; index++)
{
}


    private void ShowResults();
{
}

    }

If you put in 9 in to Number of Values to sum? then it going to come up like 9 lines that say for example value no 1 and so on to no 9 that you can enter your number you want in to it.
I don't understand how i'm going to put it in. i know how to do it if you know the value of it but now it is 0 so i dont know how i can make it

I'm looking at this, but the first thing I see is a typo on line 44 (the semi-colon).
Also the closing brace on 19 needs to be moved to 47 or 49.
Also, C# is case-sensitive, so your numOfInPut should match the case of NumOfInPut.

...and if this was meant to be the main module of a console app, you're missing Main().
Did you accidentally delete it?

Edited 4 Years Ago by thines01: clarity

Your code seems to be all messed up.
You got to use an Array or better a List to store your inputted numbers
Write an input loop for that.
Then loop trough your array or list and sum all the numbers.

Have a look at this and let us know if it needs clarifying:

public void Implementation()
        {
            int mySum = GetNumbers(GetNumberCount()).Sum();
        }
        public int GetNumberCount()
        {
            int iCount = 0;
            Console.WriteLine("Enter number of values to sum: ");
            while (int.TryParse(Console.ReadLine(), out iCount) == false || iCount <= 0)
                Console.WriteLine("Invalid number, try again");
            return iCount;
        }
        public List<int> GetNumbers(int numCount)
        {
            List<int> returnList = new List<int>();
            for (int i = 0; i < numCount; i++)
            {
                int iValue = 0;
                Console.WriteLine("Enter Number " + (i + 1).ToString() + ":");
                while (int.TryParse(Console.ReadLine(),out iValue) == false)
                    Console.WriteLine("Invalid number, try again");
                returnList.Add(iValue);
            }
            return returnList;
        }

Edited 4 Years Ago by skatamatic: n/a

thx for the help. i have one questien. if i want to type in numbers in to a loop like this Console.WriteLine("What is the number you want nr " +index ); when it start it goung to say What is the number you want nr 1 and after one i want to put in a number how do i do it?

thx for it but is it a way to get it next to it and not under it?

Using .WriteLine() implies that you want to start a newline (it automatically appends Environment.Newline to the end of the string). You should use .Write() instead if you want to achieve this functionality.

Yes, just put it next to it.
Are you using Visual Studio to edit your code?

using System;

namespace DW_409292_CS2_CON
{
   class Program
   {
      static void Main(string[] args)
      {
         Console.WriteLine("Enter a number");
         string strData = Console.ReadLine().Trim();
         int intData = 0;

         if (!int.TryParse(strData, out intData))
         {
            Console.WriteLine("Invalid number: " + strData);
            return;
         }

         Console.WriteLine(intData.ToString() + " is a nice number");
      }
   }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class WholeNumbersFor
    {
        private int numOfInPut = 0;
        private int sum = 0;

        public void start()
        {

            WriteProgramInfo();
            ReadInPut();
            SumNumbers();
            ShowResults();
        }
        private void ReadInPut()
        {

            Console.Write("Number of Values to sum?");
            try
            {

                numOfInPut = int.Parse(Console.ReadLine().Trim());
            }
            catch
            {
                Console.WriteLine("Enter valid number");
            }
            Console.WriteLine();
        }
        private void WriteProgramInfo()
        {
            Console.WriteLine("\n\n ++++++ Summation of whole numbers ++++++");
            Console.WriteLine();

        }
        private void SumNumbers()
        {

            int index;
            int temp = 0;


            for (index = 0; index < numOfInPut; index++)
            {
                try
                {
                    Console.WriteLine("Enter the" + index.ToString() + "th Value");
                    temp = int.Parse(Console.ReadLine().Trim());
                    if (temp == 0)
                    {
                        index--;
                    }
                    else
                    {
                        sum += temp;
                    }
                }
                catch
                {
                    Console.WriteLine("enter Valid integer");
                    index--;
                }
            }
        }

        private void ShowResults()
        {
            Console.WriteLine("\n\n ++++++ Summation of whole numbers is"+ sum.ToString() +" ++++++");
            Console.WriteLine();
        }
    }
}

Edited 3 Years Ago by Dani: Formatting fixed

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