Can anyone help with this?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • torres1
    New Member
    • Mar 2010
    • 2

    #1

    Can anyone help with this?

    Hi,

    I am creating a windows application showing name date of birth and number of heartbeats from date of birth to a particular targetdate. My program is showing name and date of birth but i cannot get the program to work out the calculations. i have declared the variables at the top as beats per day and beats per week etc, i was wondering if anyone can help me as on how to get the program to calculate all these values once the enter button is pressed? here is my code, many thanks

    Code:
    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 q3
    {
        public partial class Form1 : Form
        {
            int bpd;
            int bpw;
            int bpm;
            int bpy;
            int bted;
            int enb;
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void btnenter_Click(object sender, EventArgs e)
            {
                bpd = 70 * 23;
                bpw = 1680 * 5;
                bpm = 11760 * 6;
                bpy = 47040 * 13;
                bted = 564480 * 39;
                enb = 22456560 + 16800;
    
    
            }
    
    
    
            private void txtheartbeats_TextChanged(object sender, EventArgs e)
            {
                txtheartbeats.Text = "enb";
            }
    
            private void txtname_TextChanged(object sender, EventArgs e)
            {
                txtname.Text = "John Smith";
            }
    
            private void txtDob_TextChanged(object sender, EventArgs e)
            {
                txtDob.Text = "05/10/1990";
    
            }
    
            private void txtTargetdate_TextChanged(object sender, EventArgs e)
            {
                txtTargetdate.Text = "11/10/2020";
            }
    
    
    
        }
    }
    Last edited by Frinavale; Apr 22 '10, 02:23 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    It's obvious this is some kind of homework assignment and it's against forum policy for you to ask for help on this kind of thing. That said, you can ask for syntax help and it seems to me that you might not have a lot of programming experience.

    I'd highly suggest you head over to the insights forum and read through the tutorials posted by Tlhintoq. http://bytes.com/topic/c-sharp/insights/, look for the Building an Application series.

    Your calculations in the code you posted are all hard coded. You need to learn about getting user input and using it in calculations with variables.

    That's all I can really do to help you... good luck!

    Comment

    • Monomachus
      Recognized Expert New Member
      • Apr 2008
      • 127

      #3
      Originally posted by GaryTexmo
      It's obvious this is some kind of homework assignment and it's against forum policy for you to ask for help on this kind of thing. That said, you can ask for syntax help and it seems to me that you might not have a lot of programming experience.

      I'd highly suggest you head over to the insights forum and read through the tutorials posted by Tlhintoq. http://bytes.com/topic/c-sharp/insights/, look for the Building an Application series.

      Your calculations in the code you posted are all hard coded. You need to learn about getting user input and using it in calculations with variables.

      That's all I can really do to help you... good luck!
      I would also suggest using DateTimePicker controls for Dates and also when calculating the difference between Dates use TimeSpan class.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        I would strongly recommend that you name your variables something that is easier to understand. I tried to help with this but I couldn't tell what the following variables were representing:
        Code:
                 int bpd;
                 int bpw;
                 int bpm;
                 int bpy;
                 int bted;
                 int enb;
        It's unfair to just post a bunch of code and say "it's not working can you figure it out" especially when we have no idea what your logic is supposed to do...or even what your variables mean.


        Why do you think your application is not working?
        Are you seeing any error messages?
        If you are, what line is the error occurring on?
        If you don't see an error message, what is your application doing or not doing?
        What have you tried to fix the problem?
        Have you tried stepping through your code with the debugger to see what's going on?

        -Frinny

        Comment

        • tlhintoq
          Recognized Expert Specialist
          • Mar 2008
          • 3532

          #5
          I suspect your program is calculating just fine when you click the button.

          Code:
           private void btnenter_Click(object sender, EventArgs e)
                  {
                      bpd = 70 * 23;
                      bpw = 1680 * 5;
                      bpm = 11760 * 6;
                      bpy = 47040 * 13;
                      bted = 564480 * 39;
                      enb = 22456560 + 16800; 
                  }
          You just aren't doing anything with the values after you do the calculations. You do all the math, then exit the method.

          Learning Visual Studio is not helping you with the coding of your homework, so here's a VS tip. Put a breakpoint on the first line of the button.click method. Then run the program. You should see your program stop on this line when you click the button. You will then have to press the F10 key to step through the method line by line. You will see the values of these variable in the locals and autos pallets.

          Comment

          • tlhintoq
            Recognized Expert Specialist
            • Mar 2008
            • 3532

            #6
            I would strongly recommend that you name your variables something that is easier to understand. I tried to help with this but I couldn't tell what the following variables were representing:
            Code:
             int bpd;
                     int bpw;
                     int bpm;
                     int bpy;
                     int bted;
                     int enb
            ;
            Frinny is right. ASCII characters are free, and there is no global shortage. You don't have to conserve on letters when creating your variables. When you or someone else comes back to work on your program a year from now
            BeatsPerMinute is a lot more descriptive than bpm

            Comment

            Working...