Click here to Skip to main content
15,883,921 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EvenandOdds
{
    class Program
    {
        static void Main(string[] args)
        {
            List<double> even = new List<double>();
            List<double> odd = new List<double>();

            Console.Write("odd: ");
            Random randomNums = new Random();

            for (int i = 0; i < 25; i++) ;
            {
                odd.Add(randomNums.Next(0,100));

                Console.WriteLine();

            }
             Console.ReadLine();

            }
        }
    }


What do I put in that last WriteLine to show the odd numbers?
Posted
Updated 31-Oct-11 9:27am
v3

Well, you do not check if the number is odd. To do that do something like :

C#
bool isOdd = num % 2 != 0;


Use a local variable there and assign the random number to this local. Then you can easily show it using Console.WriteLine. Or access the last item using list[count - 1].
 
Share this answer
 
v3
Comments
André Kraak 31-Oct-11 15:31pm    
my 5, took me to long to find the MSDN % operator link.
Nish Nishant 31-Oct-11 15:32pm    
Yeah, MSDN is not easy to search huh? :-)
Sergey Alexandrovich Kryukov 31-Oct-11 17:24pm    
First, one needs to know what is MSDN... My 5 for the answer.
--SA
You need to check for odd numbers, which you can do with the % operator[^].
C#
int Num = 5;

if(Num % 2 == 0)
{
  // It's even

}
else
{
  // It's odd

}
 
Share this answer
 
Comments
Nish Nishant 31-Oct-11 15:33pm    
Voted 5 as well. We posted at the same time I guess.
André Kraak 31-Oct-11 15:35pm    
Thanks.
Member 8349150 31-Oct-11 15:41pm    
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EvenandOdds
{
class Program
{
static void Main(string[] args)
{

int random;

List<double> even = new List<double>();
List<double> odd = new List<double>();



Console.Write("odd: ");
Random randomNums = new Random();



for (int randomm = 0; randomm < 25; randomm++)
{
odd.Add(randomNums.Next(0, 100));

bool isOdd = randomm % 2 != 0;

Console.WriteLine(odd[randomm].ToString());
Console.ReadLine();

}
}


}
}

Does not work too well but I tried what you said
Sergey Alexandrovich Kryukov 31-Oct-11 17:25pm    
...and you did not explain what's "not too well".
--SA
Sergey Alexandrovich Kryukov 31-Oct-11 17:25pm    
Sure, a 5.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900