4
Answers

If - Else

In the following Program when zone1 or zone2 and quantity less or equal to 10 delivery is free. But Program is giving following wrong result. Please fix the error.

Zone 1
Quantity 9
Not free


using System;
namespace DemoORAndAND
{
class Program
{
static void Main(string[] args)
{
const int ZONE1 = 1, ZONE2 = 2;
const int LOWQUANTITY = 10;
int quantity;
int diliveryZone;

Console.WriteLine("Delivery is free for zone {0} or {1}", ZONE1, ZONE2);

Console.WriteLine("...when the number of boxes is less than {0}", LOWQUANTITY);

quantity = method("\nZone ");
diliveryZone = method("Quantity ");

if ((diliveryZone == ZONE1 || diliveryZone == ZONE2) && quantity <= LOWQUANTITY)
Console.WriteLine("Free");
else
Console.WriteLine("Not free");

Console.ReadKey();
}
public static int method(string s)
{
int num;

Console.Write(s);
num = Convert.ToInt32(Console.ReadLine());
return num;
}
}
}

Answers (4)