write, compile and test a short program to read in a list of 10 positive numbers which also determines and prints out the largest number.

here's what i've got so far. but how do i change it in order for it to accept a positive number only?

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int [] numbers = new int[10] ;
            int largest = 0;
            
            for (int I = 0; I <= 9; I++)
            {
                
                Console.WriteLine("Enter a number"); //Writes the specified data, followed by the current line terminator, to the standard output stream.

                numbers[I] = int.Parse(Console.ReadLine());
                Console.WriteLine();
                if (numbers[I] > largest)
                    largest = numbers[I];
            }

            Console.WriteLine("The largest number entered is " + largest.);
            Console.ReadLine();//Reads a line of characters from the current stream and returns the data as a string.

        }

    }
}

There are two steps. First, use the uint type. Second, validate the input string against the uint type before saving it:

uint value;

Console.Write("Enter a positive integer: ");

while (!uint.TryParse(Console.ReadLine(), out value))
    Console.Write("Invalid input. Enter a positive integer: ");

numbers[I] = value;

You're comparing your number with largest to obtain the largest one ...
What are the positive numbers - the numbers, which are bigger than 0 ..

There are two steps. First, use the uint type. Second, validate the input string against the uint type before saving it:

uint value;

Console.Write("Enter a positive integer: ");

while (!uint.TryParse(Console.ReadLine(), out value))
    Console.Write("Invalid input. Enter a positive integer: ");

numbers[I] = value;

where do i put the above within my own code?

where do i put the above within my own code?

Use some common sense. Given that my snippet performs the same operation as the part of your code that parses a line and stores the result in numbers[I] , that's a good place to start experimenting.

Total = 0
Do Until number = -1
Console.Write(“Enter a positive value; -1 to terminate: ”)
Number = Console.ReadLine()
Total += number
Loop
Console.WriteLine(Total)


help me to define the error and plez help to correct it
This segment should read an unspecified number of positive values from the user and sum them. Assume that number and total are declared as Integer.

Reformulate your question in a new thread, you might get an answer!
Do not resurrect old threads!

And considering this thread already has an answer to that question; read it and don't start a new thread >.<

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.