CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2013
    Posts
    1

    Small C# programming problem

    I am just getting to learn c# and I am attempting to calculate different times and prices associated to a movie theater type of calculation but when I choose two different times it add the first time chosen and prices and multiplies it by the new time and amount instead of adding the two different times together. Some information to help fix my problem will be greatly appreciated.

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            double ctix;
            double atix;
            double stix;
            double price;
            double price1;
            double tax;
            double total1;
           
    
            ctix = Convert.ToDouble(TextBox2.Text);
            atix = Convert.ToDouble(TextBox3.Text);
            stix = Convert.ToDouble(TextBox4.Text);
    
            if (CheckBox1.Checked == true)
            {
                ctix = ctix * 5.00;
                atix = atix * 5.00;
                stix = stix * 5.00;
            };
    
            if (CheckBox2.Checked == true || CheckBox3.Checked == true)
            {
                ctix = ctix * 6.50;
                atix = atix * 6.50;
                stix = stix * 6.50;
    
            };
    
            if (CheckBox4.Checked == true || CheckBox5.Checked == true)
            {
                ctix = ctix * 6.50;
                atix = atix * 9.50;
                stix = stix * 7.00;
                
            };
    
            
            price = ctix + atix + stix;
    
            price1 = price * .835;
    
            tax = price - price1;
    
            total1 = price + tax;
    
            TextBox5.Text = price.ToString();
            TextBox6.Text = tax.ToString();
            TextBox7.Text = total1.ToString();
    
    
    
    
    
    
    
    
        }
    }

  2. #2
    Join Date
    May 2013
    Posts
    1

    Re: Small C# programming problem

    Hi itgrowsind,

    I'm trying to understand where the problem is but I'm having trouble identifying your controls. Could you rename your textboxes and checkboxes to proper identification names. It's a good practice to make variables and control names as descriptive as possible, especially if you're working in a group on a single project. I personally use the UI_ControlType_ControlPurpose naming system. For example, if you have a textbox that accepts a firstname, the name of the textbox will be UI_Tb_FName.

    Another thing is this piece of code:
    Code:
    if (CheckBox1.Checked == true)
            {
                ctix = ctix * 5.00;
                atix = atix * 5.00;
                stix = stix * 5.00;
            };
    It's always good to imitate a professional, whether you are one or not. Employers love it
    Your code can be rewritten as follows
    Code:
    if (CheckBox1.Checked)
            {
                ctix = ctix * 5.00;
                atix = atix * 5.00;
                stix = stix * 5.00;
            };
    Since "Checked" is a boolean property, you don't need operators. (A false condition would be !CheckBox1.Checked)

    Again, I'm sorry for not being able to answer your question specifically but I hope after your create some sort of naming system for your controls I'll be able to help you.

    Good luck.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured