the question was :
The application should ask the user for the total number of tickets to be booked. while the booking the tickets if the total number of booked tickets exceeds the available tickets, the application should raise an exception. I don’t know why it is not showing an error when I do this I came up with this solution:
using System;
namespace Ticket
{
class blah
{
public void abc()
{
int numberOfTickets;
int numberOfAvailableTickets=10;
int cost = 100;
int pay;
Console.WriteLine("how many tickets do you need");
numberOfTickets = Convert.ToInt32(Console.ReadLine());
try
{
if (numberOfTickets < numberOfAvailableTickets)
{
pay = 100 * numberOfTickets;
Console.WriteLine("Pay please");
Console.WriteLine(pay);
}
}
if( numberOfTickets>numberOfAvailableTickets)
{
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}
}
class Theater
{
static void Main(string[] args)
{
blah hi = new blah();
hi.abc();
Console.ReadLine();
}
}
}
I am not even sure that the code you show even compiles… try this
It
throws anExceptionif the the entered number exceeds the available tickets…