-4

I was wondering why this piece of code is not outputting even or odd would I need to add a readline statement after the ternary operation

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

namespace tenary
{
    class Program
    {
        static void Main(string[] args)
        {
            string input; int a;
            Console.WriteLine("Enter a number: ");
            input = Console.ReadLine();
            a = int.Parse(input);
            input = (a % 2 == 0) ? "Even" : "Odd";
            Console.ReadLine();
        }
    }
}
user2005549
  • 231
  • 2
  • 3
  • 4
  • You're not outputing anything, only reading.add the line: Console.WriteLine("Your number is: "+input); before the last Console.ReadLine(); – Fragment Feb 12 '15 at 03:25
  • never mind I Just figured it out – user2005549 Feb 12 '15 at 03:25
  • 1
    The code is not outputting anything because you have not included a statement where you output your result. You just overwrite `input` with the result of your ternary expression. Try adding `Console.WriteLine(input)` at the end. – Asad Saeeduddin Feb 12 '15 at 03:25

1 Answers1

0

You don't have any code that writes to the console after you do the modulus check.

Try adding Console.WriteLine(input); after your ternary

Alexis Murray
  • 678
  • 13
  • 23