Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Dental : Form
    {
        public Dental()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {




            if (TxtName.Text.Equals(""))
            {
                MessageBox.Show("Please enter your name", "Incorrect Info", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

            }

            else if ((TxtOther.Text.Equals("")) && (ChkOther.Checked   == true))
            {
                MessageBox.Show("Please enter an amount for other", "Incorrect Info", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

            }









            else if  ((((ChkCleaning.Checked == false) &&
            (ChkXray.Checked = false) && (ChkCavity.Checked == false) &&
            (ChkFluoride.Checked = false) &&
            (ChkRootCanal.Checked = false) &&
            (ChkOther.Checked = false))))
            {
                MessageBox.Show("Please check at least one checkbox!", "Incorrect Info", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

            }


            else if (ChkOther.Checked == false)
            {
                TxtOther.Text = "";
            }


























            else


            {
                int total;
                int other;
                total = 0;



                other = Int32.Parse(TxtOther.Text);



            if (ChkCleaning.Checked == true)
            {
                total += 35;
                LblTotal.Text = String.Format("{0:C}", total);

            }

            if (ChkCavity.Checked == true)
            {
                total += 150;
                LblTotal.Text = String.Format("{0:C}", total);

            }

            if (ChkXray.Checked == true)
            {
                total += 85;
                LblTotal.Text = String.Format("{0:C}", total);

            }


           if (ChkFluoride.Checked == true)
            {
                total += 50;
                LblTotal.Text = String.Format("{0:C}", total);

            }


            if (ChkRootCanal.Checked == true)
            {
                total += 225;
                LblTotal.Text = String.Format("{0:C}", total);

            }


            if (ChkOther.Checked == true)
            {
                total += other;
                LblTotal.Text = String.Format("{0:C}", total);


            }

            LblTotal.Text = String.Format("{0:C}", total);







            }


        }

        private void button2_Click(object sender, EventArgs e)
        {
            ChkCleaning.Checked = false;
            ChkCavity.Checked = false;
            ChkXray.Checked = false;
            ChkFluoride.Checked = false;
            ChkRootCanal.Checked = false;
            ChkOther.Checked = false;
            TxtName.Text = "";
            TxtOther.Text = "";


        }
    }
}
Posted
Comments
Member 11190214 4-Nov-14 10:06am    
Also when none of the checkboxes are checked the message box I set does not pop up. All help is appreciated!!
ZurdoDev 4-Nov-14 10:19am    
Just debug it and see what is happening.

1 solution

Ok,the problem i guess is here:

C#
else if  ((((ChkCleaning.Checked == false) &&
            (ChkXray.Checked = false) && (ChkCavity.Checked == false) &&
            (ChkFluoride.Checked = false) &&
            (ChkRootCanal.Checked = false) &&
            (ChkOther.Checked = false))))


If you look closely, you can see that some of the clauses have an assigment operator(=) instead of an equality operator(==). Change that to:

C#
else if  ((((ChkCleaning.Checked == false) &&
            (ChkXray.Checked == false) && (ChkCavity.Checked == false) &&
            (ChkFluoride.Checked == false) &&
            (ChkRootCanal.Checked == false) &&
            (ChkOther.Checked == false))))


and I think it should work.

P.S. Debugging is your friend. Don't forget it :)
 
Share this answer
 
v2
Comments
ZurdoDev 4-Nov-14 11:34am    
+5 for debugging their code for them.
Pikoh 4-Nov-14 11:45am    
Well, i know i shouldn't, but sometimes a mistake like this can make you lose a lot of time cause does not throw any error. At least OP made a question and provided source code :)
BillWoodruff 4-Nov-14 11:47am    
+5 good work !

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