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. Web Development
  3. ASP.NET
  4. problem in simple calculation

problem in simple calculation

Scheduled Pinned Locked Moved ASP.NET
csharpasp-nethelplearning
5 Posts 2 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 Offline
    J Offline
    jacal99
    wrote on last edited by
    #1

    hi i am new to c# programming and i am getting problem in asp.net i am trying to make simple division in two fields and get their result in the thired textbox on a button click. this is my code void Button2_Click(object sender, EventArgs e) { int val = int.Parse(tb1.Text); lbl1.Text = val.ToString(); int a = int.Parse(total_fee.Text); int b = int.Parse(c_length.Text); int c = int.Parse(your_amount.Text); your_amount.Text = c.ToString(a/b); } Total Fee:

    Course Length:

    Your balance: Mazhar Hussain

    R 1 Reply Last reply
    0
    • J jacal99

      hi i am new to c# programming and i am getting problem in asp.net i am trying to make simple division in two fields and get their result in the thired textbox on a button click. this is my code void Button2_Click(object sender, EventArgs e) { int val = int.Parse(tb1.Text); lbl1.Text = val.ToString(); int a = int.Parse(total_fee.Text); int b = int.Parse(c_length.Text); int c = int.Parse(your_amount.Text); your_amount.Text = c.ToString(a/b); } Total Fee:

      Course Length:

      Your balance: Mazhar Hussain

      R Offline
      R Offline
      Ryan Bost
      wrote on last edited by
      #2

      If you are attempting to divide a by b and supply it to the your_amount textbox, then use the following code (your code modified).... int a = int.Parse(total_fee.Text); int b = int.Parse(c_length.Text); your_amount.Text = (string)(a/b); If you want to make sure your code accomodates when c_length is zero, then use the following code... int a = int.Parse(total_fee.Text); int b = int.Parse(c_length.Text); your_amount.Text = b==0 ? 0 : (string)(a/b); Ryan Bost http://www.sugarcoding.com

      J 1 Reply Last reply
      0
      • R Ryan Bost

        If you are attempting to divide a by b and supply it to the your_amount textbox, then use the following code (your code modified).... int a = int.Parse(total_fee.Text); int b = int.Parse(c_length.Text); your_amount.Text = (string)(a/b); If you want to make sure your code accomodates when c_length is zero, then use the following code... int a = int.Parse(total_fee.Text); int b = int.Parse(c_length.Text); your_amount.Text = b==0 ? 0 : (string)(a/b); Ryan Bost http://www.sugarcoding.com

        J Offline
        J Offline
        jacal99
        wrote on last edited by
        #3

        Hi Ryan you modify my code but it is not working ... it is giving me the same error that Compiler Error Message: CS0030: Cannot convert type 'int' to 'string' on this line your_amount.Text = (string)(a/b); any other brights ideas ... me waiting ... Mazhar Hussain

        R 1 Reply Last reply
        0
        • J jacal99

          Hi Ryan you modify my code but it is not working ... it is giving me the same error that Compiler Error Message: CS0030: Cannot convert type 'int' to 'string' on this line your_amount.Text = (string)(a/b); any other brights ideas ... me waiting ... Mazhar Hussain

          R Offline
          R Offline
          Ryan Bost
          wrote on last edited by
          #4

          Sorry Mazhar... ...try this instead... your_amount.Text = (a/b).ToString(); Ryan Bost http://www.sugarcoding.com

          J 1 Reply Last reply
          0
          • R Ryan Bost

            Sorry Mazhar... ...try this instead... your_amount.Text = (a/b).ToString(); Ryan Bost http://www.sugarcoding.com

            J Offline
            J Offline
            jacal99
            wrote on last edited by
            #5

            Hi Ryan ... :-) buddy the code works ... thx now i can do my job easy ... thx again ... seea bye Mazhar Hussain

            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