Make a program in C# in which take no. of items, price of items, quantity of items and name of items (Use 2D Array):
Make a program in C# in which take no. of items, price of items, quantity of items and name of items as input from the user and give the discount according to the following conditions (Use 2D Array):
a. If from Bahria University give discount of 30%.
b. Else if the total amount is greater than 50,000 and less than 100,000 give discount of 20%.
c. Else if the total amount is greater than 100,000 give discount of 30%.
CODE:
Console.WriteLine("Number of items do you want to add");
int add = Convert.ToInt32(Console.ReadLine());
string[,] array1 = new string[add, 3];
for (int i = 0; i < add; i++)
{
Console.WriteLine("\t\tEnter Detail Of Product:{0}", i + 1);
Console.WriteLine("Enter Product name:");
array1[i, 0] = Console.ReadLine();
Console.WriteLine("Enter Product Quantity:");
array1[i, 1] = Console.ReadLine();
Console.WriteLine("Enter Product Prices");
array1[i, 2] = Console.ReadLine();
}
double totalamt = 0;
for (int i = 0; i < add; i++)
{
double price = double.Parse(array1[i, 1]);
int quantity = int.Parse(array1[i, 2]);
totalamt += price * quantity;
}
double disamt = 0;
Console.WriteLine("you belongs to bahria university(yes/no)");
string answer = Convert.ToString(Console.ReadLine().ToLower());
if (answer == "yes")
{
disamt = totalamt * 0.3;
}
else if (totalamt > 50000 && totalamt < 100000)
{
disamt = totalamt * 0.2;
}
else if (totalamt > 100000)
{
disamt = totalamt * 0.4;
}
Console.WriteLine("**************************");
Console.WriteLine("ITEMS DETAIL");
Console.WriteLine("**************************");
for (int i = 0; i < add; i++)
{
Console.WriteLine("Name: {0}", array1[i, 0]);
Console.WriteLine("Quantity: {0}", array1[i, 1]);
Console.WriteLine("Price:{0}", array1[i, 2]);
Console.WriteLine("---------------------------------------");
}
double payment = 0;
payment = totalamt - disamt;
Console.WriteLine("Total Amount: {0}", totalamt);
Console.WriteLine("Discount: {0}", disamt);
Console.WriteLine("Final Amount: {0}", payment);
Console.WriteLine("*******************************");
Console.WriteLine("name\t quantity\t price");
for (int i = 0; i < add; i++)
{
for (int j = 0; j < add; j++)
{
Console.Write(array1[i, j] + "\t ");
}
Console.WriteLine();
}
Comments
Post a Comment