Just a little change in your code.
int number;
int min, max;
int sum = 0;
Console.WriteLine("Enter the minimum number");
min = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the maximum number");
max = Convert.ToInt32(Console.ReadLine());
if (max > min)
{
for (number = min; number <= max; number++)
{
if (number % 2 != 0)
sum = sum + number;
}
}
else
{
sum = 0;
}
Console.WriteLine(sum);
the
else
is enough and the
WriteLine
can be moved to the end to avoid dupliating.
Nice to see you were able to solve your problem by yourself.