Why am I getting an error message of “Error 1 Division by constant zero 25 17 ConsoleApplication3“
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Higher, Lower... What is the highest possible number that you're thinking of?");
string b = Console.ReadLine();
int f = int.Parse(b);// F = THE MAX #
Random computerguess = new Random();
int computerGuess = computerguess.Next(f);
Console.WriteLine(computerGuess);
Console.WriteLine("if your number is higher than the number displaid above, then press the '1' key so I guess higher. if your number is lower press the '0' (down) as in telling the comp to go down/lower");
string I = Console.ReadLine();
int G = int.Parse(I);
int H = 1/2;
if (G == 0)
{
computerGuess = computerGuess * H;
Console.WriteLine(computerGuess);
}
Console.Read();
}
}
}
You are doing an integer division:
This will be zero always. Instead use a decimal:
and then cast your
computerGuessback to int: