C# Dice game homework

Viewed 53

I have this homework and i'm have no idea of how to. do Write a game that simulates the traditional “odd or even”. The player must choose 0 for even or 1 odd pair. one must enter a value between 0 and 5, which will be compared to a random value generated by the computer. check the winner and report victory or defeat to the player

Here's what i have made:

using System;
                
public class Program
{
public static void Main()
{
Random rand = new Random();
int dice = rand.Next(6);
int eo;

    
Console.WriteLine("Choose between even ( 0 ) or odd ( 1 )");
eo = int.Parse(Console.ReadLine());
    
if ((eo == 0) && (dice /2 == 0))
{
    Console.WriteLine("Win");
}
else if ((eo == 0) && (dice /2 != 0))
{
    Console.WriteLine("Lose");
}
else if ((eo == 1) && (dice /2 != 0))
{
    Console.WriteLine("Win");
}   
else if ((eo == 1) && (dice /2 == 0))
{
    Console.WriteLine("Lose");
}   

Console.WriteLine("The randon number was: " + dice);    
    
}
}
1 Answers

How about...

if (eo == (dice & 1))
    Console.WriteLine("Win");
else
    Console.WriteLine("Lose");
Related