Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
namespace hotel_project
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            const double price1=70.00;
            const double price2=140.00;
            const double price3=210.00;
            const double price4=280.00;
            const double price5=350.00;


           double  price;
            int days;
            if (listBox1.GetSelected(0))
                price = price1;
            else
                if (listBox1.GetSelected(1))
                    price = price2;
                else
                    if (listBox1.GetSelected(2))
                        price = price3;
                    else
                        if (listBox1.GetSelected(3))
                            price = price4;
                        else
                            price = price5;

                                if (radioButton1.Checked)
                                    days = 1;
                                else
                                    if (radioButton2.Checked)
                                        days = 2;
                                    else
                                        if (radioButton3.Checked)
                                            days = 3;
                                        else
                                            if (radioButton4.Checked)
                                                days = 4;
                                            else
                                                if (radioButton5.Checked)
                                                    days = 5;
                                                else
                                                    if (radioButton6.Checked)
                                                        days = 6;
                                                    else
                                                        days = 7;

            price = price * days ;
            label9.Text = "Total is" + price.ToString("C")

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {

        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void textBox5_TextChanged(object sender, EventArgs e)
        {

        }

        private void label6_Click(object sender, EventArgs e)
        {

        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {


        }

        private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}


Here is the form screenshot http://i.imgur.com/IwITuVU.png[^]
Posted
Updated 8-Apr-14 5:51am
v2
Comments
Aneeq1 8-Apr-14 11:45am    
http://i.imgur.com/IwITuVU.png
[no name] 8-Apr-14 11:49am    
Instead of just dumping your code here, you need to describe a problem with your code or ask some sort of a question.
CHill60 8-Apr-14 12:23pm    
How can we tell what is an adult price and which is a child? Give your controls meaningful names. And remove all those empty methods from your code dump - they are not relevent
OriginalGriff 8-Apr-14 15:01pm    
And BTW: in addition to what else you have been told, sort out your indentation: it's miles out.
As it stands, it looks like your radio button checks are part of your list box *else* clause - they aren't.
A better way to indent it is:
if (listBox1.GetSelected(0))
price = price1;
else
if (listBox1.GetSelected(1))
price = price2;
else
if (listBox1.GetSelected(2))
price = price3;
else
if (listBox1.GetSelected(3))
price = price4;
else
price = price5;

if (radioButton1.Checked)
days = 1;
else
if (radioButton2.Checked)
days = 2;
else
if (radioButton3.Checked)
days = 3;
else
if (radioButton4.Checked)
days = 4;
else
if (radioButton5.Checked)
days = 5;
else
if (radioButton6.Checked)
days = 6;
else
days = 7;

price = price * days;
label9.Text = "Total is" + price.ToString("C");
Or better still:
if (listBox1.GetSelected(0))
price = price1;
else if (listBox1.GetSelected(1))
price = price2;
else if (listBox1.GetSelected(2))
price = price3;
else if (listBox1.GetSelected(3))
price = price4;
else
price = price5;

if (radioButton1.Checked)
days = 1;
else if (radioButton2.Checked)
days = 2;
else if (radioButton3.Checked)
days = 3;
else if (radioButton4.Checked)
days = 4;
else if (radioButton5.Checked)
days = 5;
else if (radioButton6.Checked)
days = 6;
else
days = 7;

price = price * days;
label9.Text = "Total is" + price.ToString("C");

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900