Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. making calculator

making calculator

Scheduled Pinned Locked Moved C#
17 Posts 8 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J jessica gelina

    i have two text boxes, and four buttons. Each text box allows for numbers, the buttons are teh math function. They then print the answer onclick to a seperate label. I have tries adding the strings which simply put the two numbers in the box next to one another. I have tries sending the text.tostring function to the label.......

    S Offline
    S Offline
    Sean89
    wrote on last edited by
    #7

    You need to convert it to an int before you can add them. Use this method: int x = Convert.ToInt32(//put string number in here); int y = Convert.ToInt32(//put string number in here); // do your calculations (x*y, x+y, etc); Wacky waving inflateable arm flailing tube man! - Family Guy

    J 1 Reply Last reply
    0
    • S Sean89

      You need to convert it to an int before you can add them. Use this method: int x = Convert.ToInt32(//put string number in here); int y = Convert.ToInt32(//put string number in here); // do your calculations (x*y, x+y, etc); Wacky waving inflateable arm flailing tube man! - Family Guy

      J Offline
      J Offline
      jessica gelina
      wrote on last edited by
      #8

      int x; int y; private void btnAdd_Click(object sender, System.EventArgs e) { int x = Convert.ToInt32.txtFirstNum; int y = Convert.ToInt32.txtSecondNum; x + y; } It doesn't recoginze the ToInt32! Is this supposed to be my answer label name?

      J N C 3 Replies Last reply
      0
      • J jessica gelina

        int x; int y; private void btnAdd_Click(object sender, System.EventArgs e) { int x = Convert.ToInt32.txtFirstNum; int y = Convert.ToInt32.txtSecondNum; x + y; } It doesn't recoginze the ToInt32! Is this supposed to be my answer label name?

        N Offline
        N Offline
        Nish Nishant
        wrote on last edited by
        #9

        jessica gelina wrote:

        int x = Convert.ToInt32.txtFirstNum; int y = Convert.ToInt32.txtSecondNum;

        :omg: Can't you at least copy/paste correctly???? Regards, Nish


        Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
        The Ultimate Grid - The #1 MFC grid out there!

        1 Reply Last reply
        0
        • J jessica gelina

          int x; int y; private void btnAdd_Click(object sender, System.EventArgs e) { int x = Convert.ToInt32.txtFirstNum; int y = Convert.ToInt32.txtSecondNum; x + y; } It doesn't recoginze the ToInt32! Is this supposed to be my answer label name?

          J Offline
          J Offline
          jessica gelina
          wrote on last edited by
          #10

          :confused: :confused: :confused:

          C 1 Reply Last reply
          0
          • J jessica gelina

            i have two text boxes, and four buttons. Each text box allows for numbers, the buttons are teh math function. They then print the answer onclick to a seperate label. I have tries adding the strings which simply put the two numbers in the box next to one another. I have tries sending the text.tostring function to the label.......

            S Offline
            S Offline
            Sean89
            wrote on last edited by
            #11

            Just need to make a few changes: private void btnAdd_Click(object sender, System.EventArgs e) { int x = Convert.ToInt32(txtFirstNum.Text); int y = Convert.ToInt32(txtSecondNum.Text); x + y; } That should fix it ;P Wacky waving inflateable arm flailing tube man! - Family Guy

            C 1 Reply Last reply
            0
            • S Sean89

              Just need to make a few changes: private void btnAdd_Click(object sender, System.EventArgs e) { int x = Convert.ToInt32(txtFirstNum.Text); int y = Convert.ToInt32(txtSecondNum.Text); x + y; } That should fix it ;P Wacky waving inflateable arm flailing tube man! - Family Guy

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #12

              Sean89 wrote:

              int x; int y;

              What's this bit for ? ( outside the click event handler ) Christian Graus - Microsoft MVP - C++

              S 1 Reply Last reply
              0
              • J jessica gelina

                i have two text boxes, and four buttons. Each text box allows for numbers, the buttons are teh math function. They then print the answer onclick to a seperate label. I have tries adding the strings which simply put the two numbers in the box next to one another. I have tries sending the text.tostring function to the label.......

                T Offline
                T Offline
                taediman naver com
                wrote on last edited by
                #13

                Good!!

                1 Reply Last reply
                0
                • I IceWater42

                  Sounds just like project 5 in the Basic Programming course at St Louis Community college. Good luck. :-D

                  A Offline
                  A Offline
                  Alomgir Miah
                  wrote on last edited by
                  #14

                  Somebody has to start somewhere. Live Life King Size Alomgir Miah

                  1 Reply Last reply
                  0
                  • J jessica gelina

                    :confused: :confused: :confused:

                    C Offline
                    C Offline
                    Colin Angus Mackay
                    wrote on last edited by
                    #15

                    He is referring to the fact that you coded:

                    Convert.ToInt32.txtFirstNum;

                    When the example clearly used brackets and specified you needed to pass in a string.

                    Convert.ToInt32(txtFirstNum.Text);

                    ColinMackay.net Scottish Developers are looking for speakers for user group sessions over the next few months. Do you want to know more?

                    1 Reply Last reply
                    0
                    • J jessica gelina

                      int x; int y; private void btnAdd_Click(object sender, System.EventArgs e) { int x = Convert.ToInt32.txtFirstNum; int y = Convert.ToInt32.txtSecondNum; x + y; } It doesn't recoginze the ToInt32! Is this supposed to be my answer label name?

                      C Offline
                      C Offline
                      Colin Angus Mackay
                      wrote on last edited by
                      #16

                      In addition to my previous post.

                      jessica gelina wrote:

                      x + y;

                      Needs to assign the result to something in order for you to use it. e.g.

                      int result = x + y;

                      Then you can take the result and assign it to the Text property of your Label. (Remember to convert it to a string when you do that) Does this help? ColinMackay.net Scottish Developers are looking for speakers for user group sessions over the next few months. Do you want to know more?

                      1 Reply Last reply
                      0
                      • C Christian Graus

                        Sean89 wrote:

                        int x; int y;

                        What's this bit for ? ( outside the click event handler ) Christian Graus - Microsoft MVP - C++

                        S Offline
                        S Offline
                        Sean89
                        wrote on last edited by
                        #17

                        Ohh lol oops. private void btnAdd_Click(object sender, System.EventArgs e) { int x = Convert.ToInt32(txtFirstNum.Text); int y = Convert.ToInt32(txtSecondNum.Text); x + y; } Sorry bout that. Wacky waving inflateable arm flailing tube man! - Family Guy

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups