Write a program in C-Sharp to generate E-Bill using Switch Case.

The switch statement is a control statement that handles multiple selections and enumerations by passing control to one of the case statements within its body as the following example:

int caseSwitch = 1;
switch (caseSwitch)
{
case 1:
Console.WriteLine("Case 1");
break;
case 2:
Console.WriteLine("Case 2");
break;
default:
Console.WriteLine("Default case");
break;
}

Control is transferred to the case statement which matches the value of the switch. The switch statement can include any number of case instances, but no two case statements can have the same value. Execution of the statement body begins at the selected statement and proceeds until the break statement transfers control out of the case body. A jump statement such as a break is required after each case block, including the last block whether it is a case statement or a default statement. With one exception, (unlike the C++ switch statement), C# does not support an implicit fall through from one case label to another. The one exception is if a case statement has no code.

If no case expression matches the switch value, then control is transferred to the statement(s) that follow the optional default label. If there is no default label, control is transferred outside the switch. Here come's the E-Billing code in C-Sharp,

using System;
using System.Collections.Generic;
using System.Text;

namespace Assignment1
{
class Program
{
static void Main(string[] args)
{
double total_amount;
l: Console.WriteLine("Enter from following choices.\n\n1.Press One For Demostic\n2.Press Two For Commercial\n3.Press Three For Industrial");
Console.Write("\n\nYou hava entered the choice: ");
int choice = int.Parse(Console.ReadLine());
if (choice == 1 || choice == 2 || choice == 3)
{
r: Console.Write("\nEnter Previous Reading: ");
long previous_reading = long.Parse(Console.ReadLine());
Console.Write("Enter Present Reading: ");
long present_reading = long.Parse(Console.ReadLine());
if (present_reading > previous_reading)
{
long total_reading = (present_reading - previous_reading);
switch (choice)
{
case 1:
if (total_reading >= 0 && total_reading <= 50) { total_amount = total_reading * 1.50; Console.WriteLine("\nThe Amount For Total Reading {0} units Is Rs.{1}/-", total_reading, total_amount); } else if (total_reading >= 51 && total_reading <= 100) { total_amount = total_reading * 2.0; Console.WriteLine("\nThe Amount For Total Reading {0} units Is Rs.{1}/-", total_reading, total_amount); } else if (total_reading > 100)
{
total_amount = total_reading * 2.50;
Console.WriteLine("\nThe Amount For Total Reading {0} units Is Rs.{1}/-", total_reading, total_amount);
}
break;
case 2:
if (total_reading >= 0 && total_reading <= 50) { total_amount = total_reading * 2.50; Console.WriteLine("\nThe Amount For Total Reading {0} units Is Rs.{1}/-", total_reading, total_amount); } else if (total_reading >= 51 && total_reading <= 100) { total_amount = total_reading * 3.0; Console.WriteLine("\nThe Amount For Total Reading {0} units Is Rs.{1}/-", total_reading, total_amount); } else if (total_reading > 100)
{
total_amount = total_reading * 3.50;
Console.WriteLine("\nThe Amount For Total Reading {0} units Is Rs.{1}/-", total_reading, total_amount);
}
break;
default:
if (total_reading >= 0 && total_reading <= 50) { total_amount = total_reading * 3.50; Console.WriteLine("\nThe Amount For Total Reading {0} units Is Rs.{1}/-", total_reading, total_amount); } else if (total_reading >= 51 && total_reading <= 100) { total_amount = total_reading * 4.0; Console.WriteLine("\nThe Amount For Total Reading {0} units Is Rs.{1}/-", total_reading, total_amount); } else if (total_reading > 100)
{
total_amount = total_reading * 4.50;
Console.WriteLine("\nThe Amount For Total Reading {0} units Is Rs.{1}/-", total_reading, total_amount);
}
break;

}
}
else
{
Console.WriteLine("\nInvalid Input Reading....");
Console.Write("\nWould You Like To Continue Y or N: ");
string d = Console.ReadLine();
if (d == "y" || d == "Y")
{
goto r;
}
else
{
Console.WriteLine("Your Good For Nothing.....");
}
}
}
else
{
Console.WriteLine("\nInvalid Input");
Console.Write("\nWould You Like To Continue Y or N: ");
string d = Console.ReadLine();
if(d == "y" || d == "Y")
{
goto l;
}
else
{
Console.WriteLine("Your Good For Nothing.....");
}
}
Console.ReadLine();
}
}
}



Output:
Enter from following choices.

1.Press One For Demostic
2.Press Two For Commercial
3.Press Three For Industrial


You hava entered the choice: 1

Enter Previous Reading: 23598
Enter Present Reading: 23958

The Amount For Total Reading 360 units Is Rs.900/-

0 comments:

Post a Comment

 

About Me

It's Me!Hi, I'm Moinuddin. I'm a Software Engineer at WIPRO working on Microsoft .NET Technology. I'm interested in a wide range of technology topics, mainly Microsoft including Windows Azure, WCF, WPF, Silverlight and any other cool technology that catches the eye.

Site Info

ProjectCSharp.com is mainly about demonstrating real time examples in different technologies like ASP.NET, WCF, WPF, Silverlight, Azure etc..,

Followers

Help Links

Project CSharp (C#) Copyright © 2011. All Rights Reserved.