Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to 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 31-Oct-11 10:23am
Edited 31-Oct-11 10:27am
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Well, you do not check if the number is odd. To do that do something like :
 
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].
  Permalink  
v3
Comments
André Kraak at 31-Oct-11 15:31pm
   
my 5, took me to long to find the MSDN % operator link.
Nishant Sivakumar at 31-Oct-11 15:32pm
   
Yeah, MSDN is not easy to search huh? :-)
SAKryukov at 31-Oct-11 17:24pm
   
First, one needs to know what is MSDN... My 5 for the answer.
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You need to check for odd numbers, which you can do with the % operator[^].
int Num = 5;
 
if(Num % 2 == 0)
{
  // It's even

}
else
{
  // It's odd

}
  Permalink  
Comments
Nishant Sivakumar at 31-Oct-11 15:33pm
   
Voted 5 as well. We posted at the same time I guess.
André Kraak at 31-Oct-11 15:35pm
   
Thanks.
Member 8349150 at 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 even = new List();
List odd = new List();
 

 
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
SAKryukov at 31-Oct-11 17:25pm
   
...and you did not explain what's "not too well".
--SA
SAKryukov at 31-Oct-11 17:25pm
   
Sure, a 5.
--SA
André Kraak at 31-Oct-11 17:39pm
   
Thanks.

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

  Print Answers RSS
0 OriginalGriff 375
1 Sergey Alexandrovich Kryukov 329
2 CPallini 260
3 DamithSL 214
4 Maciej Los 197
0 OriginalGriff 5,455
1 DamithSL 4,457
2 Maciej Los 3,885
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,115


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 31 Oct 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100