Sunday, 15 September 2013

Creating a method

Creating a method

protected void calculateRateButton_Click(object sender, EventArgs e)
{
//declare variables and retrieve user inputs
int nbPeopleInt;
string roomTypeString;
int nbNightsInt;
nbNightsInt = int.Parse(nbNightsTextBox.Text);
nbPeopleInt = int.Parse(nbPeopleDropDownList.Text);
roomTypeString = roomTypeDropDownList.Text;
int totalFareInt = calculateRoomBooking(roomTypeString, nbPeopleInt,
nbNightsInt);
}
private int calculateRoomBooking(string RoomType, int nbNights, int
nbPeople)
{
int totalFareInt = 0;
int dailyRateInt = 0;
// set daily rate based on selected room type
switch (RoomType)
{
case "Standard":
dailyRateInt = 100;
break;
case "Superior":
dailyRateInt = 150;
break;
case "Luxury":
dailyRateInt = 175;
break;
}
// calculation of booking rate
totalFareInt = dailyRateInt * nbNightsInt + 10 * (nbPeopleInt - 1)
* nbNightsInt;
// display booking rate
totalRateTextBox.Text = totalFareInt.ToString();
}
protected void roomDetailsButton_Click(object sender,
ImageClickEventArgs e)
{
// go to room details page
Response.Redirect("RoomDetails.aspx");
}
}
however, it always say that dailyRateInt, nbNightsInt, nbPeopleInt is not
defined with this line:
totalFareInt = dailyRateInt * nbNightsInt + 10 * (nbPeopleInt - 1) *
nbNightsInt;
But I did define them above as you guys can see
please helps

No comments:

Post a Comment