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. C# Code for a calculation

C# Code for a calculation

Scheduled Pinned Locked Moved C#
helpcsharpsaleslearning
11 Posts 7 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.
  • C Cali1999

    Hi Everyone, I'm learning C# and am stuck on writing code for a calculation. Here's the parameters: Calculate and display the price. The calculations will require price per hour. My project has the customer name input, item rented input x the # of hours rented = total cost. Pressing the calculate button will perform this function. Any help here would be appreciated. Thanks jeff

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #2

    Sounds like a homework assignment, so here are only some hints: Create a textbox for the price and a textbox for the # of hours (a NumericUpDown control may be better for the latter, no string-to-number conversion required there). Create a button clicked event handler for the calculate button and do the calculation there. You can convert from the textbox string to decimal/integer via Decimal.TryParse[^] or Int32.TryParse[^] method, respectively. regards

    P 1 Reply Last reply
    0
    • C Cali1999

      Hi Everyone, I'm learning C# and am stuck on writing code for a calculation. Here's the parameters: Calculate and display the price. The calculations will require price per hour. My project has the customer name input, item rented input x the # of hours rented = total cost. Pressing the calculate button will perform this function. Any help here would be appreciated. Thanks jeff

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #3

      So... the schools have started again... ;) The calculation part of the code is very easy: price = pricePerHour * hours; So, is that really where your problem lies?

      Despite everything, the person most likely to be fooling you next is yourself.

      L P 2 Replies Last reply
      0
      • G Guffa

        So... the schools have started again... ;) The calculation part of the code is very easy: price = pricePerHour * hours; So, is that really where your problem lies?

        Despite everything, the person most likely to be fooling you next is yourself.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #4

        Guffa wrote:

        So, is that really where your problem lies?

        Nah, I don't think they teach programming in 4th grade. ;)

        1 Reply Last reply
        0
        • C Cali1999

          Hi Everyone, I'm learning C# and am stuck on writing code for a calculation. Here's the parameters: Calculate and display the price. The calculations will require price per hour. My project has the customer name input, item rented input x the # of hours rented = total cost. Pressing the calculate button will perform this function. Any help here would be appreciated. Thanks jeff

          C Offline
          C Offline
          Cali1999
          wrote on last edited by
          #5

          P. S. //Calculate the total cost of charter by number of hours X selected yacht x the rate per hour. The above is the calculation I was thing of using. I'm having trouble coding it. Jeff

          C 1 Reply Last reply
          0
          • L Lost User

            Sounds like a homework assignment, so here are only some hints: Create a textbox for the price and a textbox for the # of hours (a NumericUpDown control may be better for the latter, no string-to-number conversion required there). Create a button clicked event handler for the calculate button and do the calculation there. You can convert from the textbox string to decimal/integer via Decimal.TryParse[^] or Int32.TryParse[^] method, respectively. regards

            P Offline
            P Offline
            Paul Conrad
            wrote on last edited by
            #6

            Greeeg wrote:

            Sounds like a homework assignment

            His post down further in the thread really make me suspicious, it sounds like a problem I use in my class, and the funny thing is, my class doesn't start for a few more weeks.

            "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

            D 1 Reply Last reply
            0
            • P Paul Conrad

              Greeeg wrote:

              Sounds like a homework assignment

              His post down further in the thread really make me suspicious, it sounds like a problem I use in my class, and the funny thing is, my class doesn't start for a few more weeks.

              "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

              D Offline
              D Offline
              Dan Neely
              wrote on last edited by
              #7

              fratboy trying to repair damage to the cheat library before school restarts because a helpful student cleaner tossed them all over the summer? :laugh:

              Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall

              P 1 Reply Last reply
              0
              • G Guffa

                So... the schools have started again... ;) The calculation part of the code is very easy: price = pricePerHour * hours; So, is that really where your problem lies?

                Despite everything, the person most likely to be fooling you next is yourself.

                P Offline
                P Offline
                Paul Conrad
                wrote on last edited by
                #8

                Guffa wrote:

                the schools have started again...

                Maybe. My class doesn't start for a few more weeks, and the OP's problem sounds very similar to one of my homework problems I give out, and this particular won't be assigned until the middle of October. Sorry, no credit given to the OP for two reasons: 1. I don't accept early work, 2. Wrong language, not a C# class ;P

                "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

                1 Reply Last reply
                0
                • D Dan Neely

                  fratboy trying to repair damage to the cheat library before school restarts because a helpful student cleaner tossed them all over the summer? :laugh:

                  Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall

                  P Offline
                  P Offline
                  Paul Conrad
                  wrote on last edited by
                  #9

                  Yep. Like I just told Guffa, my very similar problem is usually assigned about mid-October for the Fall term. People may look to the assistance of my former students are going to be in for a rude surprise. After about 2 years of teaching this class, I am doing a complete overhaul of it :-\

                  "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

                  1 Reply Last reply
                  0
                  • C Cali1999

                    P. S. //Calculate the total cost of charter by number of hours X selected yacht x the rate per hour. The above is the calculation I was thing of using. I'm having trouble coding it. Jeff

                    C Offline
                    C Offline
                    carbon_golem
                    wrote on last edited by
                    #10

                    I think Guffa very kindly answered (solved) your coding dilemma. But but here it is stated another way...

                    HAI
                    CAN HAS STDIO?
                    I HAS A rate ITZ NUMBAR
                    I HAS A hours ITZ NUMBAR
                    LOL ducketsOwed R rate TIEMZ hours
                    VISIBLE ducketsOwed
                    KTHXBYE

                    Seriously though, are you having trouble setting up the project or what? I don't get it, your questions is solved, but you restated the question... what more do you need?

                    “It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.” -Edsger Dijkstra

                    1 Reply Last reply
                    0
                    • C Cali1999

                      Hi Everyone, I'm learning C# and am stuck on writing code for a calculation. Here's the parameters: Calculate and display the price. The calculations will require price per hour. My project has the customer name input, item rented input x the # of hours rented = total cost. Pressing the calculate button will perform this function. Any help here would be appreciated. Thanks jeff

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

                      *********** U need to Learn Do your homework by yoursellf ********** double total = Convert.ToDouble(TextBox_item_rented.Text) * Convert.ToDouble(TextBox_cost_per_hour.Text); TextBox_total=total.ToString(); MessageBox.Show("Total Cost for customer "+ TextBox_cust_name.Text + "= " + total); *********** U need to Learn Do your homework by yoursellf ********** :sigh: :zzz: :zzz: :zzz:

                      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